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.

asmelsenewthis
autoenumoperatorthrow
boolexplicitprivatetrue
breakexportprotectedtry
caseexternpublictypedef
catchfalseregistertypeid
charfloatreinterpret_casttypename
classforreturnunion
constfriendshortunsigned
const_castgotosignedusing
continueifsizeofvirtual
defaultinlinestaticvoid
deleteintstatic_castvolatile
dolongstructwchar_t
doublemutableswitchwhile
dynamic_castnamespacetemplate

 

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.