C++ Identifiers and Keywords

Prev     Next

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


asm else
Auto enum
Break extern
Case float
Catch for
Char friend
Class goto
Const if
Continue inline
Default int
Delete long
Double new
operator Template
private This
protected Throw
public try
register typedef
return union
short unsigned
signed virtual
sizeof void
static volatile
struct while

Prev     Next

Like it? Please Spread the word!