The C++ comments are used to insert notes into the source code and are meant only to enhance the readability of the code. The C++ comments are statements that are not executed by the compiler. .
There are two types of comments in C++.
The single line comment starts with //
(double slash) and causes the compiler to ignore everything that follows the slashes on the same line. Let's see an example of single line comment in C++.
#include <iostream> using namespace std; int main() { int x = 11; // x is a variable cout<<x<<"\n"; }
The C++ multi line comment is used to comment multiple lines of code. It is surrounded by slash and asterisk (/∗ ..... ∗/
). Everything within the opening /∗
and the closing ∗/
is a comment, even if it stretches over multiple lines. Let's see an example of multi line comment in C++.
#include <ostream> using namespace std; int main() { /* declare and print variable in C++. */ int x = 35; cout<<x<<"\n"; }