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
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