C++ Comments

C++ Comments

C++ Comments – C++ introduces a new comments symbol //(double slash).
Comments start with a double slash symbol and terminate at the end of the line. A comment many start anywhere in the line and whatever follows till the end of the line is ignored.
Note that there is no closing symbol.
The double slash comments are basically a single line comment. Multi line comments can be written as follows.
//This is an example of
//C++ program is illustrate
//some of its features

The C comments symbols /*,*/ are still valid and are more suitable for multi-line comments. The following comment is allowed.
/* this is an example of
C++ program to illustrate
Some of its features
*/
You can use either or both styles in our programs. Since this tutorial on C++ we will use only the C++ style.
However, remember that we cannot insert a // style comment within the text of a program line. For example, the dabble slash comment cannot be used in a manner as shown below.
For(j=0; j<n ; /*loops n times */ j++)

C++ comments using in a program demo

// this is single line comment
/* this is multiple
Line comment*/
#include <iostream.h>
void main()
{
/* This is comment in C++ example. */
cout <<” This is comment  example ”;
}

When to use C++ comments

Comments are almost always a good thing. Most programmers don’t use enough of them. If you are tempted to leave out comments, remember that not everyone is as smart as you; they may need more explanation that you do about what you program is doing. Also, you may not be as smart next month, when you have forgotten key details of your program’s operation, as you are today.
Use comments to explain to the person looking at the listing what you’re trying to do. The details are in the program statements themselves, so the comments should concentrate on the big picture, clarifying your reason for using a certain statement.

Leave a Reply

Your email address will not be published.