Site icon TestingDocs.com

C++ Comments

Overview

C++ comments are explanatory notes that the developer adds to the program source code. These notes will help others to understand the code and the logic.

C++ comments are ignored by the compiler. They are meant for humans to increase the readability of the code. C++ supports two types of comments:

Line comment

Single line comment starts with // and may extend to the end of the line.

// This is an example single line comment

Multi-line comment

C++ multi-line comments start with /* and end with */ and can span multiple lines. This comment is mostly used for blocks of code like program header, function header, etc.

/*

*  This is a sample multi-line

*  C++ comment.

*/

 

Example

In the example, the first comment is a multi-line comment. We can include information like author name, program description, file name, date, change history, etc. Commercial programs may also include license and copyright information.

 

/************************************
* C++ Comments
* Filename: comments.cpp
* C++ Tutorials - www.TestingDocs.com
* This is an example of multi-line
* comment
*************************************/
#include 
using namespace std;
// Example of single line comment
int main()
{
    int studentNo; // valid identifier
    studentNo = 1001;
    cout << studentNo << endl;
    return 0;
} // end main


C++ Tutorials

C++ Tutorials on this website:

https://www.testingdocs.com/c-coding-tutorials/

For more information on the current ISO C++ standard

https://isocpp.org/std/the-standard

Exit mobile version