C Tutorial
Control statement
C Loops
C Arrays
C String
C Functions
C Structure
C Pointer
C File
C Header Files
C Preprocessors
C Misc
Using #else preprocessor directive with C
#else preprocessor directive in C is used with #if preprocessor. When the expression of #if is not true then the code under #else will be executed. Here we will see the syntax and C program using this preprocessor directive.
You may have seen our previous guide about #if preprocessor directive. The syntax of #else is given bellow with #if preprocessor.
// syntax of #else preprocessor directive
#if condition
//code to execute when #if condition is true
#elseif condition
// code to execute when #elseif is true
#else
// execute the code if above condition is false
#endif
C program using #else preprocessor directive
The program bellow will execute the code bellow the #else preprocessor as #if is not true here. Let’s see the program bellow;
// C program using #else preprocessor directive
#include <stdio.h>
#define SYSTEM 1
int main(){
#if SYSTEM == 0
printf("SYSTEM value is = %d\n", SYSTEM);
#else
print("SYSTEM value is non-zero.\n");
#endif
return 0;
}
Output of program :
SYSTEM value is non-zero.
Previous page:Â #if preprocessor directive
Next page:Â #ifdef preprocessor directive