Comment in C++

Find this useful? Support us: Star on GitHub 6
Category: Other | Language: C++

In C++, comments are used for documentation purposes. They are ignored by the compiler and serve to explain the code to other programmers and yourself.

There are two ways to write comments in C++:

1. // Single-line comment: Anything written after ‘//’ is considered a comment and extends until the end of the line. For example:

``C++
// This is a single-line comment in C++
cout << "Hello, World!" << endl; // Another comment here


2. /* Multi-line comment */: Anything written between
/* and */ is considered a comment. This type of comment can span multiple lines. For example:

C++
/*
This is a multi-line comment in C++
It can span across several lines
*/
cout << "Hello, World!" << endl; /* Another type of comment */
``

It is good practice to use comments to explain the purpose of your code and any important details that might be overlooked by others who read your code.