Keywords in C++

There are some reserved words in C++ that we cannot use as identifiers. These words have special meaning and perform a predetermined task. We call them keywords in C++.

Keywords in C++

There are 32 keywords in C++, that are also present in C programming Language. These 32 keywords have been listed here.

 

autodoubleintstruct
breakelselongswitch
caseenumregistertypedef
charexternreturnunion
constfloatshortunsigned
continueforsignedvoid
defaultgotosizeofvolatile
doifstaticwhile

 

You may read: Break and Continue in C++

Reserved words in C++

Besides these 32 keywords, there are another 30 reserved words in C++ that are not present in C. These keywords are given below.

 

asmdynamic_castnamespacereinterpret_casttry
boolexplicitnewstatic_casttypeid
catchfalseoperatortemplatetypename
classfriendprivatethisusing
const_castinlinepublicthrowvirtual
deletemutableprotectedtruewchar_t

There are 11 more keywords that are not essential when we are using standard ASCII character set but they provide more readable alternatives for some of the C++ operators. They are also used to facilitate programming with character sets that lack characters needed by C++. These 11 reserved words have been listed here.

 

andcomplor_eq
and_eqnotxor
bitandnot_eqxor_eq
bitoror

As we have discussed earlier, we cannot use these keywords for identifiers i.e. variables names, function names. If we do so, the compiler will throw an error.

See the code here.

#include <iostream>

int main()
{
  //while is a reserved keyword
  //using while as a variable
  int while=9; 
  //trying to print  value stored in while variable
  std::cout<<while;
  return 0;
  //the compiler will throw an error
}

Output:

Error

Thank you.

Leave a Reply

Your email address will not be published. Required fields are marked *