C++ Keywords and Comments
This topic discusses about the keywords and comments for the C++ programming language. Once we get these basic concepts we can continue with the advanced features of the language.
C++ Keywords
There are certain words with a specific meaning in C++ which tell (i.e. help) the compiler what the program is supposed to do. These Keywords cannot be used as variable names, class names, or method names. Keywords in C++ are case sensitive, all characters being lower case.
Keywords are reserved words that are predefined in the language; see the table below. All the keywords are in lowercase.
| asm | else | new | this |
| auto | enum | operator | throw |
| bool | explicit | private | true |
| break | export | protected | try |
| case | extern | public | typedef |
| catch | false | register | typeid |
| char | float | reinterpret_cast | typename |
| class | for | return | union |
| const | friend | short | unsigned |
| const_cast | goto | signed | using |
| continue | if | sizeof | virtual |
| default | inline | static | void |
| delete | int | static_cast | volatile |
| do | long | struct | wchar_t |
| double | mutable | switch | while |
| dynamic_cast | namespace | template |
The “keywords” are marked in red color as shown in the sample code below:
#include <iostream> // This is a header
using namespace std // This is a header
int main() {
/* The code below will print
some text to the screen */
cout << "Hello from TechGuru!";
return 0;
}
C++ Comments
Comments are descriptions that are added to a program to make code easier to understand. The compiler simply ignores comments and hence it’s only for documentation of the program. C++ supports two comment styles (shown in the above program):
- Single-line comment begins with // and terminate at the end of the line.
- Multi-line comment begin with /* and terminate with */ that spans multiple lines.
NOTE: It is up to the programmers which they want to use. Generally, we use // for short comments, and /* */ for longer comments.