C++ Identifiers : Tokens

We have already seen, which are the different types of characters that are considered legal in C++. In this chapter we will be learning the token i.e basic building blocks of C++.

Tokens in C++ :

The group of characters that forms an Basic Building block is called as Token. Tokens are of following 4 types of token in C++ :

Tokens in C++

A. Token Type 1 : Identifier

Various data items with symbolic names in C++ is called as Identifiers. Following data items are called as Identifier in C++ –

  1. Names of functions
  2. Names of arrays
  3. Names of variables
  4. Names of classes

The rules of naming identifiers in C++ :

  1. C++ is case-sensitive so that Uppercase Letters and Lower Case letters are different
  2. The name of identifier cannot begin with a digit. However, Underscore can be used as first character while declaring the identifier.
  3. Only alphabetic characters, digits and underscore (_) are permitted in C++ language for declaring identifier.
  4. Other special characters are not allowed for naming a variable / identifier
  5. Keywords cannot be used as Identifier.

Some Examples of Identifier in C++ :

Identifier Validity Reason
1digit Invalid Digit at first location is not allowed
digit-1 Invalid Special characters other than underscore is not allowed
num 1 Invalid Space not allowed