C++ Identifiers and Keywords

WHAT ARE C++ IDENTIFIERS?

In a program to identify a function, variable, class or any of the other user defined item you use identifiers so, this concept is known as Identifiers. The identifier can be started with a letter ‘A’ to ‘Z’ or ‘a’ to ‘z’ or from underscore (_) which is followed by zero or more letters, underscores and digits (0 to 9). The C++ does not allow punctuation characters such as $, % and @ within identifiers. Some of the valid identifiers are: shyam, _max, j_47, name10.

And invalid identifiers are :

4xyz, x-ray, abc 2.

RULES FOR NAMING IDENTIFIER

  • Identifiers are case sensitive because C++ is case sensitive i.e. uppercase letters and lowercase letters are different.
  • You cannot start name of an identifier with a digit whereas underscore can be used as first character while naming identifier.
  • Other special characters are not allowed while naming an identifier.
  • You cannot use keywords as identifier.

WHAT ARE KEYWORDS?

Keywords are the reserved identifiers that cannot be used as names for the variables in a program. The keywords cannot be used for:

  • Declaring the class name
  • Declaring the object name
  • Declaring the variable name
  • Declaring the function name

KEYWORDS

A keyword is a reserved word. You cannot use it as a variable name, constant name etc. A list of Keywords in C++ Language are given below.