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

C #ifndef

#ifndef预处理程序指令检查宏是否未由#define定义。如果是,则执行代码,否则执行#else代码(如果存在)。
语法:
#ifndef MACRO
//code
#endif
带有#else的语法:
#ifndef MACRO
//successful code
#else
//else code
#endif

C #ifndef示例

让我们看一个使用#ifndef预处理程序指令的简单示例。
#include <stdio.h>
#include <conio.h>
#define INPUT
void main() {
int a=0;
#ifndef INPUT
a=2;
#else
printf("Enter a:");
scanf("%d", &a);
#endif       
printf("Value of a: %d\n", a);
getch();
}
输出:
Enter a:5
Value of a: 5
但是,如果您未定义INPUT,它将执行#ifndef代码。
#include <stdio.h>
#include <conio.h>
void main() {
int a=0;
#ifndef INPUT
a=2;
#else
printf("Enter a:");
scanf("%d", &a);
#endif       
printf("Value of a: %d\n", a);
getch();
}
输出:
Value of a: 2
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4