Difference between return 1, return 0, return -1 and exit?

后端 未结 6 471
终归单人心
终归单人心 2020-12-22 22:17

For example consider following code:

int main(int argc,char *argv[])
{
   int *p,*q;
   p = (int *)malloc(sizeof(int)*10);
   q = (int *)malloc(sizeof(int)*1         


        
6条回答
  •  别那么骄傲
    2020-12-22 22:43

    return in function return execution back to caller and exit from function terminates the program.

    in main function return 0 or exit(0) are same but if you write exit(0) in different function then you program will exit from that position.

    returning different values like return 1 or return -1 means that program is returning error .

    When exit(0) is used to exit from program, destructors for locally scoped non-static objects are not called. But destructors are called if return 0 is used.

提交回复
热议问题