Oops! It appears that you have disabled your Javascript. In order for you to see this page as it is meant to appear, we ask that you please re-enable your Javascript!

CPP (C plus plus) Tokens

CPP (C plus plus) Tokens

What is Tokens?

A token is the smallest identifiable and individual unit in any program.  or another definition is that a token is the smallest element of a C++ program that is meaningful to the compiler.

Main Types of Token in C++

There are five types of tokens in C++ language:

  1. Keywords
  2. Variables/Identifiers
  3. Constants/Literals
  4. Punctuators
  5. Operators

1. Keywords

Keywords is reserved words which have fixed meaning. The meaning and working of these keywords are already known to the compiler. These words should be written in lowercase letters.

Example of the keyword used in C++ are int, float, char, double, long, void, for, while, do, if, else etc. 

2. Variables/Identifiers

Identifiers or variables are names given to different variables, structures, and functions. It is a name used to represent a variable constant, array name, function name, class, object name etc.  Variables are identifier whose value can be changed is known as a variable. 

Example of a variable can be declared as shown below.

      int price;

      float tax;

3. Constants/Literals

Constants are like a variable but its value never changes during execution. The constant values used in C++ are known as literals, there are four type of literals in C++ Programming. 

  1.          i) Integer constant:-
             A value written without fraction part is called an integer constant.
             Example: 425, -7322, 10 etc.

              ii) Floating constant:- 

A value written with fraction part is floating value. Value of this type can also exponent form. Example: 9.54, -3.343, 2.11E10

iii) A character constant:- 

A single character written within single quotation marks is called character constant.
Example: ‘k’, ‘3’, ‘@’ etc.

  1. iv) String constant:-
    It is an array of characters enclosed in double quotation marks called string.
    Example: “welcome”, “12-Sep-16”

4. Punctuators

mostly used for formatting statements and expressions in C++ language.
Examples are   { }   [ ]    , *:  = etc.

5. Operators

C++ operator is a symbol that is used to perform mathematical or logical manipulations like Arithmetical operators, Relational operators etc.