C语言教程
C语言控制语句
C语言函数
C语言数组
C语言指针
C语言字符串
C语言数学函数
C语言结构
C语言文件处理
C预处理器

C #if

#if预处理程序指令对表达式或条件求值。如果condition为true,则执行代码,否则执行#elseif或#else或#endif代码。
语法:
#if expression
//code
#endif
带有#else的语法:
#if expression
//if code
#else
//else code
#endif
带有#elif和#else的语法:
#if expression
//if code
#elif expression
//elif code
#else
//else code
#endif

C #if示例

让我们看一个使用#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
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4