Comments and Keyword
Comments allow programmers to make the code more understandable and readable.
With the help of comments, vital information about the corresponding line of code is written, so that even a non-programmer can understand the logic used.
Every programming language supports some form of comments, C++ supports two types of comments, and these are:
- Single – Line Comments
- Multi-Line Comments
1. Single – Line Comments:
A Single – Line C++ comment starts with //
cout << "Hello World"; // prints Hello World
When the above code is compiled, it will ignore
// prints Hello World
And final executable code will produce the following result:
However, a Single – Line C++ comment spans only to a single line, so if you write anything like this, then it will not be a comment:
// C++ Comment Line 1
Here, Line 2 is not treated as a comment, but as an executable C++ statement.
2. Multi-Line Comments:
Multi-Line C++ comments start with /* and end with */
/* This is a comment */
/*Multi – Line C++ comments can also
Span in multiple lines
Here, everything written between the starting (/*) and ending (*/) symbols is treated as a C++ comment.
The C++ compiler ignores everything written within the comments, thus it is never executed.
Keywords are the words that cannot be used as the names for any constant, variable or an identifier in C++.
It is so because these words already have some predefined meaning to the C++ compiler.
The C++ Keywords are: