Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Comments on C+


May 11, 2021 C++


Table of contents


Comments for C+

Comments for programs are explanatory statements that you can include in your code, which improves the readability of the source code. All programming languages allow some form of annotation.

Single-line and multi-line comments are supported in C+ All characters in the comment are ignored by the C++ compiler.

The comments in C++ start with /?and end with ./. For example:

/* 这是注释 */

/* C++ 注释也可以
 * 跨行
 */

Comments can also start with // until the end of the line. For example:

#include 
using namespace std;

main()
{
   cout << "Hello World"; // 输出 Hello World     return 0; 
} 

When the above code is compiled, the compiler ignores // prints Hello World and ends up with the following results:

Hello World

Inside the /? and // comments, the // character has no special meaning. I n the // comment, the /? and s/ characters also have no special meaning. T herefore, you can nest another comment within one comment. For example:

/* 用于输出 Hello World 的注释

cout << "Hello World"; // 输出 Hello World  */