
上QQ阅读APP看书,第一时间看更新
Comments
In C++, it is possible to insert comments to describe and clarify the meaning of the program. The comments are ignored by the compiler (every comment is replaced by a single space character). There are two types of comments: line comments and block comments. Line comments start with two slashes and end at the end of the line.
cout << "Hello, World!" << endl; // Prints "Hello, World!".
Block comments begin with a slash and an asterisk and end with an asterisk and a slash. A block comment may range over several lines.
/* This is an example of a C++ program. It prints the text "Hello, World!" on the screen. */ #include <iostream> using namespace std; void main() { cout << "Hello, World!" << endl; // Prints "Hello, World!". }
Block comments cannot be nested. The following example will result in a compile-time error.
/* A block comment cannot be /* nested */ inside another one. */
A piece of advice is that you use the line comments for regular comments, and save the block comments for situations when you need to comment a whole block of code for debugging purposes.