Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      EXIT_SUCCESS, EXIT_FAILURE

      From cppreference.com
      <c‎ |program
       
       
      Program support utilities
      Program termination
      EXIT_SUCCESSEXIT_FAILURE
      Unreachable control flow
      Communicating with the environment
      Memory alignment query
      Signals
      Signal types
      Non-local jumps
      Types
       
      Defined in header<stdlib.h>
      #define EXIT_SUCCESS /*implementation defined*/
      #define EXIT_FAILURE /*implementation defined*/

      TheEXIT_SUCCESS andEXIT_FAILURE macros expand into integral constant expressions that can be used as arguments to theexit function (and, therefore, as the values to return from themain function), and indicate program execution status.

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

      Contents

      [edit]Notes

      BothEXIT_SUCCESS and the value zero indicate successful program execution status (seeexit), although it is not required thatEXIT_SUCCESS equals zero.

      [edit]Example

      Run this code
      #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

      [edit]References

      • C23 standard (ISO/IEC 9899:2024):
      • 7.22/3 General utilities <stdlib.h> (p: TBD)
      • C17 standard (ISO/IEC 9899:2018):
      • 7.22/3 General utilities <stdlib.h> (p: 248)
      • 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>

      [edit]See also

      C++ documentation forEXIT_SUCCESS,EXIT_FAILURE
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=c/program/EXIT_status&oldid=178295"

      [8]ページ先頭

      ©2009-2025 Movatter.jp