C Standard Library

C <stdlib.h> - EXIT_FAILURE constant

The C <stdlib.h> EXIT_FAILURE is a macro constant that expands to an integer expression that can be used as arguments to the exit function and indicates that the application has failed.

The opposite meaning can be specified with EXIT_SUCCESS.

In the <stdlib.h> header file, it is defined as follows:

#define EXIT_FAILURE /*implementation defined*/          


Consider the example below where the program tries to open the file test.txt. The program fails to open this file and after that it prints the message and exits using exit(EXIT_FAILURE) statement.

#include <stdio.h>
#include <stdlib.h>
int main (){
  //open the file in read mode
  FILE *pFile = fopen("test.txt", "r");

  if (pFile == NULL){
    printf("Error opening file");
  } else {
    printf("File is opened successfully."); 

  printf("This line is not executed."); 
  return EXIT_SUCCESS;

The output of the above code could be:

Error opening file

❮ C <stdlib.h> Library