search

Home  >  Q&A  >  body text

c++使用assert()断言之后,后面的变量所占用的内存是怎么清理的哦?

#include <assert.h>
#include <cstdio>

int main()
{
    int a = 1;
    assert(a < 1 && "wrong here");
    printf("come here\n");
    int b = 2;
    return 0;
}

代码如上。。请问在一段程序中,如果中途使用assert(),然后程序直接中断了,那么在assert后面的那些变量是怎么清理的哦?

天蓬老师天蓬老师2814 days ago613

reply all(3)I'll reply

  • 巴扎黑

    巴扎黑2017-04-17 13:37:55

    is not cleaned up, assert actually does not return , and the program is immediately interrupted. After the program is interrupted, the operating system reclaims all resources of this process. In the severe case of the operating system, it is not possible to distinguish between a and What the hell is "wrong here"? It's just a piece of memory.

    reply
    0
  • PHP中文网

    PHP中文网2017-04-17 13:37:55

    The variables within the

    function are all local variables, and the memory of the variable is allocated on the stack. For a,b, the memory of the variable is allocated at the beginning. If you exit normally from the main function, then Normal release. If you exit abnormally directly, there is no need to clean up. .
    You can see the difference between exit,return and other functions to exit the program. .

    reply
    0
  • PHPz

    PHPz2017-04-17 13:37:55

    If assert() is used midway and the program is directly interrupted, how are the variables after assert cleared?

    The operating system directly reclaims the memory used by this program.

    reply
    0
  • Cancelreply