EXIT_FAILURE

EXIT_SUCCESS, EXIT_FAILURE

Defined in header <stdlib.h>
#define EXIT_SUCCESS /*implementation defined*/
#define EXIT_FAILURE /*implementation defined*/

The EXIT_SUCCESS and EXIT_FAILURE macros expand into integral expressions that can be used as arguments to the exit function (and, therefore, as the values to return from the main function), and indicate program execution status.

Constant Explanation
EXIT_SUCCESS successful execution of a program
EXIT_FAILURE unsuccessful execution of a program

Notes

Both EXIT_SUCCESS and the value zero indicate successful program execution status (see exit), although it is not required that EXIT_SUCCESS equals zero.

Example

#include <stdio.h>
#include <stdlib.h>
 
int main(void)
{
    FILE *fp = fopen("data.txt","r");
    if (fp == NULL)
    {
       fprintf(stderr,"fopen() failed in file %s at line # %d", __FILE__,__LINE__);
       exit(EXIT_FAILURE);
    }
 
    /* Normal processing continues here. */
    fclose(fp);
    printf("Normal Return\n");
 
    return EXIT_SUCCESS;
}

Output:

fopen() failed in file main.cpp at line # 9

References

  • C11 standard (ISO/IEC 9899:2011):
    • 7.22/3 General utilities <stdlib.h> (p: 340)
  • C99 standard (ISO/IEC 9899:1999):
    • 7.20/3 General utilities <stdlib.h> (p: 306)
  • C89/C90 standard (ISO/IEC 9899:1990):
    • 4.10 General utilities <stdlib.h>

See also

C++ documentation for EXIT_SUCCESS, EXIT_FAILURE

© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
http://en.cppreference.com/w/c/program/EXIT_status

在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部