我是靠谱客的博主 俭朴柜子,这篇文章主要介绍C语言 #if 0,#if 1,#else,#endif,现在分享给大家,希望可以做个参考。

https://blog.csdn.net/wwwsssZheRen/article/details/79077141

 

在C语言中时常会用到#if 0,#if 1,#else,#endif语句,语句如下所示:

#if 0

    code1

#else

    code2

#endif

 

此时code1的语句被注释掉了,永远没有办法执行,而code2是被编译的;如果将#if 0变为#if 1,code1被编译,而code2永远没有办法被执行。

 

测试程序一:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
#include <stdio.h> int main() { //#if 0 // printf("#if 0n"); #if 1 printf("#if 1n"); #else printf("#elsen"); #endif return 0; }

效果一如下:

#if 1

 

 

测试程序二:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
#include <stdio.h> int main() { #if 0 printf("#if 0n"); //#if 1 // printf("#if 1n"); #else printf("#elsen"); #endif return 0; }

效果二如下:

#else

最后

以上就是俭朴柜子最近收集整理的关于C语言 #if 0,#if 1,#else,#endif的全部内容,更多相关C语言内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(61)

评论列表共有 0 条评论

立即
投稿
返回
顶部