Lập trình C - C #else

Chỉ thị tiền xử lý  #else

Chỉ thị tiền xử lý #else đánh giá biểu thức hoặc điều kiện nếu điều kiện của #if là sai. Nó có thể được sử dụng với các chỉ thị #if, #elif, #ifdef và #ifndef.

Cách 1:

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

Cách 2: có #elif

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

Ví dụ sử dụng chỉ thị tiền xử lý #else:

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

Kết quả:

Value of Number is non-zero