Comments in C++
Comments in C++
Comments in C++ are used to explain the C++ program, and to make it easy to read. It is used to prevent execution when testing alternative code. There are two types of comments that are singled-lined or multi-line comments. The comments help anyone reading the code.
C++ comment start with /* and end with */
Example of Comments
/* This is a comment */ /* C++ comments can also multiple lines */
There are two types of comments
-
- Single-line comments
- Multi-line comments
Single-line Comments in C++
Single-line comments start with two forward slashes (//). Any text between // and the end of the line will not be executed this example uses a single-line comment before a line of code
Example of single line comment
//This is comments cout<<"Hello world;
Multi-line Comments in C++
Multi-line comments start with /* and end with */ Any text between /* and */ will be ignored by the compiler
Example of multi line comment
/* The following code will print the Hello World! to the screen, and it is amazing */ cout << "Hello World!";
Read more, Operators in C++