C++ TOKENS

  • Token are the most important element to be used in creating a program.
  • The token in C++ can be defined as the smallest individual element in C++.
  • Tokens are the building block or the basic component for creating a program in the C++ language.
There are six types of tokens in C++
  1. Keywords
  2. Identifiers
  3. Literals
  4. Strings
  5. Operators

1. Keywords: Keywords are the reserved words which convey a special meaning to the language (C++) compiler. C++ language supports 31 keywords which are given below: 

asm         bool        catch          class
const_cast   delete      dynamic_cast   explicit 
export       false       friend         inline 
mutable      namespace   new            operator 
private      protected   public         reinterpret_cast
static_cast  template    this           throw
true         try         typeid         typename 
using        virtual     wchar_t 

2. Identifiers: Identifiers are fundamental building blocks of a program and are used as the general terminology for the names given to different parts of program. viz variables, functions, arrays, classes, etc.

There are certain rules that should be followed while naming C++ identifiers:

  1. They must begin with a letter or underscore(_).
  2. They must consist of only letters, digits, or underscore. No other special character is allowed.
  3. It should not be a keyword.
  4. It must not contain white space.
  5. It should be up to 31 characters long as only the first 31 characters are significant.
  6. main: method name.
  7. a: variable name.

3. Literals: Literals (often referred to as constants) are data items that are fixed data values.

There are five  types of literals that can be used in C++ :

 
  1. Integer Literal: It is used to represent integer constant.
  2. Float Literal: It is used to represent float constant.
  3. Character Literal: It is used to represent a single character.
  4. String Literal: It is used to represent the character sequence(string).
  5. Boolean Literal: It is used to represent Boolean(true or false).

4. Strings: It is a sequence of characters that ends with null characters (\0).

5. Operators: Operators are special symbols that perform specific operations on one, two, or three operands and then return a result. 

Operators in C++ can be classified into 6 types:

  1. Arithmetic Operators
  2. Relational Operators
  3. Logical Operators
  4. Bitwise Operators
  5. Assignment Operators
  6. Ternary or Conditional Operators