C++ Comments

In C++, comments are special annotations in the code that are ignored by the compiler. They are used to provide explanations, descriptions, or notes about the code to make it more understandable and maintainable. Comments are essential for documenting code, explaining complex logic, and reminding programmers of areas that need further attention.

There are two types of comments

1. Single-line comments

These comments start with // and continue to the end of the line. They are used for brief explanations.

Syntax:


// This is a single-line comment

Example:


 // Declare a variable a and initialize it to 20
int a= 20; 

Multi-line Comments

These comments start with /* and end with */. They can span across multiple lines.

Syntax:


/* This is a multi-line
   Comments */

Example:


/* This is a 
   multi-line comment
   that spans multiple lines */
int b = 50;