Detailed Explanation of #else in C Language

The #else preprocessor directive is used to evaluate the case when the #if condition is false. It can be used with the #if, #elif, #ifdef, and #ifndef directives.

Syntax:

#if expression // if code #else // else code #endif

Syntax with #elif:

#if expression // if code #elif expression // else if code #else // else code #endif
πŸ‘‡ Click to Claim πŸ‘‡
πŸ‘‰ C Language Knowledge Resource Collection

C #else Example

Let’s look at a simple example to use the #else preprocessor directive.

#include <stdio.h>
#include <conio.h>
#define NUMBER 1
void main() {
#if NUMBER==0
    printf("Value of Number is: %d", NUMBER);
#else
    printf("Value of Number is non-zero");
#endif
    getch();
}

Output:

Value of Number is non-zero

Detailed Explanation of #else in C Language


Popular Recommendations
  • C Language Tutorial – Detailed Explanation of #error in C Language

  • C Language Tutorial – Detailed Explanation of #pragma in C Language

  • C Language Algorithm – “Next Permutation” Algorithm Problem

Leave a Comment