C++ Keywords and Identifiers

C++ Keywords

C++ keywords are the reserved words which are pre-defined in C++ programming language. We cannot use keywords as an identifier. Each keyword has a pre-defined meaning for C++ compiler.

  • Trying to use a keyword as an identifier will generate a compilation error.
  • All keywords are in lower case letters.
Here is the list of reserved keywords in C++.
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 floar 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

C++ Identifiers

In C++ programming language, the name of variables, functions, labels, classes and user-defined entities are called Identifiers. Each element of a C++ program are given an identifier. A C++ identifier can be of any length, there is no limit on the length of the identifiers in C++.

For Example:
int Interest;
int getSimpleInterest(int amount);

Interest is an identifier for a variable of integer data type and getSimpleInterest is an identifier for a function. C++ identifiers are case sensitive, which means 'value' and 'Value' will be treated as two different identifiers.

Rules for Writing Identifiers
  • An identifier cannot be same as a C keyword.
  • The first character of an identifier must be either an alphabet or underscore.
  • An identifier can be composed of alphabets, digits, and underscore only.
  • Identifier name is case sensitive. "Home" and "home" is recognised as two separate identifiers.
  • Any special characters other than alphabets, digits, and underscore (such as :, . ,blank space, / are not allowed).

Here are few examples of valid and invalid Identifiers.

Valid Identifiers Invalid Identifiers
hello 1hello
Hello Hel/lo
_hello hel lo
hello_world hello,,,world