#if预处理程序指令评估表达式或条件。如果condition为true,则执行代码,否则执行#elseif或#else或#endif代码。
语法:
#if expression //code #endif
#else的语法:
#if expression //if code #else //else code #endif
#elif和#else的语法:
链接:https://www.learnfk.comhttps://www.learnfk.com/c-programming/c-preprocessor-if.html
来源:LearnFk无涯教程网
#if expression //if code #elif expression //elif code #else //else code #endif
让我们看一个使用#if预处理程序指令的简单示例。
#include <stdio.h> #include <conio.h> #define NUMBER 0 void main() { #if (NUMBER==0) printf("Value of Number is: %d",NUMBER); #endif getch(); }
输出:
Value of Number is: 0
让我们看另一个示例,以清楚地理解#if指令。
#include <stdio.h> #include <conio.h> #define NUMBER 1 void main() { clrscr(); #if (NUMBER==0) printf("1 Value of Number is: %d",NUMBER); #endif #if (NUMBER==1) printf("2 Value of Number is: %d",NUMBER); #endif getch(); }
输出:
2 Value of Number is: 1
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)