Use of exit() function

后端 未结 13 1393
离开以前
离开以前 2020-11-30 23:34

I want to know how and when can I use the exit() function like the program in my book:

#include

void main()
{
    int goals;
            


        
相关标签:
13条回答
  • 2020-12-01 00:06

    The exit function is declared in the stdlib header, so you need to have

    #include <stdlib.h>
    

    at the top of your program to be able to use exit.

    Note also that exit takes an integer argument, so you can't call it like exit(), you have to call as exit(0) or exit(42). 0 usually means your program completed successfully, and nonzero values are used as error codes.

    There are also predefined macros EXIT_SUCCESS and EXIT_FAILURE, e.g. exit(EXIT_SUCCESS);

    0 讨论(0)
提交回复
热议问题