What is the difference between exit(0) and exit(1) in C?

前端 未结 11 1825
时光取名叫无心
时光取名叫无心 2020-12-22 17:19

Can anyone tell me? What is the difference between exit(0) and exit(1) in C language?

11条回答
  •  执笔经年
    2020-12-22 17:59

    exit in the C language takes an integer representing an exit status.

    Exit Success

    Typically, an exit status of 0 is considered a success, or an intentional exit caused by the program's successful execution.

    Exit Failure

    An exit status of 1 is considered a failure, and most commonly means that the program had to exit for some reason, and was not able to successfully complete everything in the normal program flow.

    Here's a GNU Resource talking about Exit Status.


    As @Als has stated, two constants should be used in place of 0 and 1.

    EXIT_SUCCESS is defined by the standard to be zero.

    EXIT_FAILURE is not restricted by the standard to be one, but many systems do implement it as one.

提交回复
热议问题