Comments
From cppreference.com
Comments are text blocks that the compiler will ignore. Comments provide additional information that can not be easily expressed in code. They are a good way to leave notes about why the code is written as it is, since even a single programmer tends to forget things. Comments are indispensable in large programmer teams.
There are two ways to declare a comment block in C++:
- Single-line comment. The compiler always ignores everything after
//
till the end of a line. - Multi-line comment. The compiler always ignores everything between
/*
and*/
. Be sure that the comment itself does not contain*/
, because this would cause the compiler to end the comment prematurely and probably emit an error, since the rest of the comment is usually not proper C++.
The following example demonstrates the usage of comments in the "Hello world!" program:
Run this code
/* Hello world example This comment spans several lines */ #include <iostream> int main() /* This comment spans part of a line */ { std::cout << "Hello World!\n"; // till the end of the line return 0; }
Output:
Hello World!