C++ comment program comments are explanatory statements, and you can include comments in C++ code, which will improve the readability of the source code. All programming languages allow some form of annotation.

C++ supports single-line and multi-line comments. All characters in comments are ignored by the C++ compiler.

There are two kinds of C++ comments:

// – Generally used for single-line comments. / *… */ – Generally used for multi-line comments. Comments start with // and end at the end of the line. Such as:

#include <iostream> using namespace std; Int main() {// This is a comment cout << "Hello World!" ; return 0; }Copy the code

Can also be placed after a statement:

#include <iostream> using namespace std; int main() { cout << "Hello World!" ; // Output Hello World! return 0; }Copy the code

When the above code is compiled, the compiler ignores // this is a comment and prints Hello World! , the following results will be generated:

Hello World!

C++ comments start with /* and end with */. Such as:

include <iostream> using namespace std; Int main() {/* this is a comment */ /* C++ comments can also be * cross-line */ cout << "Hello World!" ; return 0; }Copy the code

The // character has no special meaning inside/and/comments. The/and/characters also have no special meaning in // comments. Therefore, you can nest one annotation within another. Such as:

/* Cout << "Hello World"; // Output Hello World */Copy the code

Block annotations (/… /) cannot be nested.

#if 0 … #endif is conditional compilation, where 0 is the argument.

Alternatively, we can use #if 0… #endif to implement comments, and can implement nested, format:

#if 0
   code
#endif 
Copy the code

You can change #if 0 to #if 1 to execute code’s code.

This format also helps with program debugging, using #if 1 to execute the test code during testing and using #if 0 to mask the test code after release.

#if can be any conditional statement.

The following code executes code1 if condition is true, and code2 otherwise.

#if condition
  code1
#else
  code2
#endif
Copy the code

Nearly sorted out some suitable for small white people entry learning materials, including e-books, tools, installation packages and so on point I

Join me in my official group

Get a full set of C language learning materials. (” ▔ ▔ / /

If you are new to C, you can share a full set of C language mastery materials with you

If you are studying C++, yes

Help you to C++ game development direction of learning, so that you think clearly, learning more effective article classification