C++ comments
Comments for a program are explanatory statements that you can include in your C++ code, which will improve the readability of the source code. All programming languages allow some form of comments.
C++ supports single-line comments and multi-line comments. All characters in comments are ignored by the C++ compiler.
C++ comments start with /* and end with */. For example:
/* 这是注释 */ /* C++ 注释也可以 * 跨行 */
Comments can also start with // and continue until the end of the line. For example:
#include <iostream> using namespace std; main() { cout << "Hello World"; // 输出 Hello World return 0; }
When the above code is compiled, the compiler will ignore the // output Hello World, and finally produce the following result:
Hello World
in /* and */ Inside the comment, the // characters have no special meaning. Within // comments, the /* and */ characters also have no special meaning. Therefore, you can nest one type of annotation within another. For example:
/* 用于输出 Hello World 的注释 cout << "Hello World"; // 输出 Hello World */