Procecessor Directive : #error

The #error preprocessor directive causes the preprocessor to stop a the location where the directive ‎is encountered  and report a fatal error. The syntax is :

Syntax :
 #error "Error Messaege"
Example 1 :
#include <stdio.h>

int main() {

  printf("Hello world\n");
  #error "This is Error Message"
  return 0;

}
Output :


Lets see another example :

Example 2 :
#include <stdio.h>

int main() {

#ifndef NUM
  #error "NUM is not defined"
#endif

  printf("%d\n", NUM);
  return 0;
}
Output :


Now if we define the NUM directive, then it will not show the error message.
#include <stdio.h>

#define NUM 100

int main() {

#ifndef NUM
  #error "NUM is not defined"
#endif

  printf("%d\n", NUM);
  return 0;
}
Output :

100


Next : C Language Tutorials List