我是靠谱客的博主 俭朴柜子,最近开发中收集的这篇文章主要介绍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永远没有办法被执行。

 

测试程序一:

#include <stdio.h>
int main()
{
//#if 0
//	printf("#if 0n");
#if 1
printf("#if 1n");
#else
printf("#elsen");
#endif
return 0;
} 

效果一如下:

#if 1

 

 

测试程序二:

#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语言 #if 0,#if 1,#else,#endif所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

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

评论列表共有 0 条评论

立即
投稿
返回
顶部