(1)
#define CHINA
#ifdef CHINA
#define BEIJING 1
#else
#define WC 1
#endif
表示:如果前面已经定义过CHINA(可以试“#define CHINA”,也可以写为#define CHINA 0等等任何的),就编译:
#define BEIJING 1
如果没有,就编译
#define WC 1
(2)
#ifndef CHINA
#define WC 1
#else
#define BEIJING 1
#endif
#ifndef与#indef意义相反:如果没有定义过xxx,就编译yyy。
(3)
#if(k>0)
aaa
#else
bbb
#endif
如果k>0就编译aaa,否则就编译bbb。与if else类似。
我们一般直接用
#if 0
aaa
#else
bbb
#endif
来注释程序段aaa。