Comments

C++ comments are hints that a programmer can add to make their code easier to read and understand. They are completely ignored by C++ compilers.

There are two ways to add comments to code:

// - Single Line Comments

/* */ -Multi-line Comments

Single Line Comments

In C++, any line that starts with // is a comment. For example,

// declaring a variable
int a;
 
// initializing the variable 'a' with the value 2
a = 2;

 

Multi-line comments

In C++, any line between /* and */ is also a comment. For example,

/* declaring a variable
to store salary to employees
*/
 
int salary = 2000;

 

Why use Comments?

If we write comments on our code, it will be easier for us to understand the code in the future. Also, it will be easier for your fellow developers to understand the code.

 

 

No comments:

Post a Comment