您好,欢迎访问一九零五行业门户网

在C语言中,条件编译是什么意思?

在c编程语言中,有几个指令控制程序代码的选择性编译。它们如下所示 −
#if#else#elif#endif#if的一般形式如下 −
#if constant_expression statement sequence#endif
#else的工作方式与c关键字else类似。
#elif表示“else if”,并建立一个if else-if编译链。
除其他外,#if还提供了一种“注释掉”代码的替代方法。
例如,
#if 0 printf("#d", total);#endif
在这里,编译器将忽略printf("#d", total);
#ifdef和#ifndef
#ifdef表示"如果定义了",并以# endif结尾。
#ifdef表示"如果未定义"。
#undef
#undef删除先前定义的定义。
#line
#line更改__line__的内容,其中包含当前编译代码的行号和__file__,它是一个包含正在编译的源文件名称的字符串。这两个都是编译器中预定义的标识符。
#pragma
#pragma指令是一个实现定义的指令,允许给编译器提供各种指令。
示例以下是c程序演示#ifdef,#ifndef,#else和#endif的示例-
live demo
# include <stdio.h># define a 10void main(){ #ifdef a printf("
hello i am here.."); #endif #ifndef a printf("
not defined "); #else printf("
r u there "); #endif}
输出当上述程序被执行时,它产生以下结果 −
hello i am here..r u there
以上就是在c语言中,条件编译是什么意思?的详细内容。
其它类似信息

推荐信息