
上QQ阅读APP看书,第一时间看更新
2.6 C++代码中的注释

程序的注释是解释性语句,C++代码中允许包含注释,这将提高源代码的可读性。所有的编程语言都允许某种形式的注释。C++支持单行注释和多行注释。注释中的所有字符会被C++编译器忽略。
用“//”作注释时,有效范围只有一行,即本行有效,不能跨行。而用“/*……*/”作注释时有效范围为多行。只要在开始处有一个“/*”,在最后一行结束处有一个“*/”即可。因此,一般习惯是内容较少的简单注释常用“//”,内容较长的常用“/*……*/”。
例如:

例如:

在“/*”和“*/”注释内部,“//”字符没有特殊的含义。在“//”注释内,“/*”和“*/”字符也没有特殊的含义。因此,可以在一种注释内嵌套另一种注释。
例如:
