Comments in C++: Single-Line & Multi-Line with Examples

Adding comments in C++ programs is considered a trait of a good programmer. You include comments in your program solely for your convenience. These comments are not part of the output, but they provide extra information about the program and help when you want to edit (modify) the program later. They help you clarify the purpose of any particular line of code. There are two ways you can add comments in your program:

One line Comments:

When you want to add a comment on a single line (just one line), you use //.

// output statement

Multi line Comments:

However, if your comment text spans more than one line, instead of writing the // symbol each time, you can write /* at the start of the text and */ at the end. Any text between these symbols will not be read by the compiler.

/* output of Marks average */

Now, let’s see where and how these can be written in your program:

#include  // header file
using namespace std; 
int main() // main Program
{
    cout << "How Are you, Mr"; // Printing Message
} /* End of Program 
  This was last statement 
  */

No Comments

Leave a Reply