Comments in C++

« Previous Chapter Next Chapter »

Program comments are explanatory statements that you can include in the C++ code that you write and helps anyone reading it's source code. All programming languages allow for some form of comments.

C++ supports single line and multi-line comments. All characters available inside any comment are ignored by C++ compiler.

C++ comments start with /* and end with */. For example:

Example

/* A comment */
/* C++ comments can  also
 * span multiple lines
 */
                                        

A comment can also start with //, extending to the end of the line. For example:

Example

#include <iostream>
using namespace std;
main()
{
   cout << "Hai Everyone"; // prints Hai Everyone
   return 0;
}
                                        

When the above code is compiled, it will ignore // prints Hai Everyone and final executable will produce following Output Will Be :

Example

Hai Everyone
                                        

Within a /* and */ comment, // characters have no special meaning. Within a // comment, /* and */ have no special meaning. Thus, you can "nest" one kind of comment within the other kind. For example:

Example

/* Comment out printing of Hai Everyone:
cout << "Hai Everyone"; // prints Hai Everyone
*/
                                        


« Previous Chapter Next Chapter »

Have Any Suggestion? We Are Waiting To Hear from YOU!

Your Query was successfully sent!