All for Joomla All for Webmasters

C #else

The #else preprocessor directive evaluates the expression or condition if condition of #if is false. It can be used with #if, #elif, #ifdef and #ifndef directives.

Syntax:

  1. #if expression
  2. //if code
  3. #else
  4. //else code
  5. #endif

Syntax with #elif:

  1. #if expression
  2. //if code
  3. #elif expression
  4. //elif code
  5. #else
  6. //else code
  7. #endif

C #else example

Let’s see a simple example to use #else preprocessor directive.

  1. #include <stdio.h>
  2. #include <conio.h>
  3. #define NUMBER 1
  4. void main() {
  5. #if NUMBER==0
  6. printf(“Value of Number is: %d”,NUMBER);
  7. #else
  8. print(“Value of Number is non-zero”);
  9. #endif       
  10. getch();
  11. }

Output:

Value of Number is non-zero
PinIt
submit to reddit

Leave a Reply

Top