Procecessor Directives : #else

The #else Conditional Compilation Directive allow us to include certain portion of the code depending upon the output of constant expression. It evaluates the expression or condition if condition of #if is false. It can be used with #if, #elif, #ifdef and #ifndef directives. The syntax is :

Syntax :
 #if Expression
   // statement to execute
 #else
   // statement to execute
 #endif
Example :
#include <stdio.h>

#define NUM 21

int main() {

#if (NUM%2 == 0)
  printf("%d is even number.\n", NUM);
#else
  printf("%d is odd number.\n", NUM);
#endif
  return 0;
}
Output :

21 is odd number.


Next : C Language Tutorials List