Procecessor Directive : #ifndef

The #ifndef is a conditional compilation directive, which allow programmers to include certain portion of the code depending upon the output of constant expression. It simply checks if the macro is defined by #define or not. If not then it executes the given statements otherwise #else code is executed, if present. The syntax is :
Syntax :
 #indef MACRONAME
   // Statements to execute
 #endif
Or
 #indef MACRONAME
   // Statements to execute
 #else
   // Statements to execute
 #endif
Example 1 :
#include <stdio.h>

#ifndef NUM
  #define NUM 100
#endif

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

100


Next : C Language Tutorials List