#ifdef #if

1514阅读 0评论2012-07-14 gududesiling
分类:C/C++

前几天碰到一个面试题,有一道是这样的:
#define Debug 0
#define Debug1 1

unsigned int a=0;

#ifdef Debug
a++;
#endif

#if Debug1
a *=2;
#endif

printf("a=%d\n",a);


其中我在这个地方迷了,就是这个#ifdef Debug 
因为前面已经定义了#define Debug 0,按常理一般认为这个ifdef不会执行,可是事实是执行了,因为这个地方无论你定义#define Debug 0,或者#define Debug 1效果都是一样的。这个地方意思是是否定义了,而是不管定义为0,或者是1.
上一篇:关于fl2440 nandflash uboot的烧写
下一篇:vi p和P命令