作用:用于对代码进行解释说明
单行注释:
\.........
多行注释:
* ......
......
...... *
嵌套注释:
#if condition
...
#endif
#if 0 cout << "branch1" << endl; //执行该语句 #else cout << "branch2" << endl; #endif #if 1 cout << "branch1" << endl; #else cout << "branch2" << endl; //执行该语句 #endif
这种形式对程序调试也可以帮助,测试时使用 #if 1 来执行测试代码,发布后使用 #if 0 来屏蔽测试代码
#if 后可以是任意的条件语句
下面的代码如果 condition 条件为 true 执行 code1 ,否则执行 code2
#if condition code1 #else code2 #endif