Comments in C++ Programming.

Comments are the text that is added in C++ code to make it more readable and easy to understand. It is basically added for future reference so that whoever is going to work on that code will get additional information from comments that help them to understand the code. The compiler treats comments as white space and completely ignores them.


Two types of comments are available in the C++ programming language, single-line comments, and multi-line comments.


Single Line Comment.

Single-line comments in C++ start with two forward slashes (//) and any text written after this till the end of the line is considered a single comment.  

Example of single-line comment in C++:

//This is a single-line comment

//initializing an integer variable with value 5
int a = 5;

int a = 10; //updating value of a


Multi-line Comment.
The multi-line comment starts in C++ start with /* and ends with */ and any text between them are considered white space and ignored by the compiler. If you start a multi-line comment by using /* but forget to close it then everything after /* will get commented on.

Example of Multi-line comment in C++:
/*Below code will print the message "Hello World on the 
console using cout function which stands for character function.
*/
std::cout<<"Hello World";

Single-line comments are mostly used for writing short comments and Multi-line comments are used for writing longer comments.

⚡ Please share your valuable feedback and suggestion in the comment section below or you can send us an email on our offical email id ✉ algolesson@gmail.com. You can also support our work by buying a cup of coffee ☕ for us.

Similar Posts

No comments:

Post a Comment


CLOSE ADS
CLOSE ADS