What is C++ Tokens?
DEFINITION: A token is the smallest identifiable and individual unit in any program. or other 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. For more detail information Click here
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. For more detail information Click here
Example of variable can be
declared as shown below.
int price;
float tax;
3. Constants/Literals
Constants are like 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. For more detail information Click here
i) Integer constant:-
A value written without fraction part is called as integer constant.
Example: 425, -7322, 10 etc.
ii) Floating constant:-
A value written without fraction part is called as 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) Character constant:-
iii) Character constant:-
A single character written within single quotation marks is called
character constant.
Example: ‘k’, ‘3’, ‘@’ etc.
Example: ‘k’, ‘3’, ‘@’ etc.
iv) String constant:-
It is an array of characters enclosed in double quotation marks called string.
Example: “welcome”, “12-Sep-16”
It is an array of characters enclosed in double quotation marks called string.
Example: “welcome”, “12-Sep-16”
4. Punctuators
Examples are { } [ ] , *: = etc.