C++ Tokens: Tokens in C++ can be defined as the smallest building block (or) the smallest unit in C++ program. Each word and punctuation can be referred to as a token in C++.
C++ Tokens
In C++ language we are having different tokens. They are as follows:
- Identifiers
- Keywords
- Constants
- Operators
- Strings
1) Identifiers
Identifiers are used for naming the variables, functions, and arrays. And we cannot use the keyword for identifiers, they are designed for special use. Once if an identifier is declared we can’t define them in the later program statements for referring to associated values. And a special kind of called the “statement label” can be used in goto statements.
The identifiers can be defined in the form of long sequence letters, digits (or) by using underscore(_).
2) Keywords
Keywords are nothing but the predefined (or) reserved words in the programming language. And each keyword is meant to perform a specific task and its meaning cannot be changed. These keywords are already known to the compiler. C++ is having more keywords than the C language.
C++ consists of totally 31 keywords. They are as follows:
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 | cwchar_t | bool |
3) Constants
Constants are similar to the variables. The main difference between them is the value of constant will be never changed once declared. Constants refer to fixed values. These are also known as “literals”.
Syntax: const data_type variable_name;
(or)
const data_type *variable_name;
Constants are of different types. They are as follows:
1) Integer constants:
Example: 0,1,153,2545
2) Real (or) Floating Point Constants:
Example: 0.0, 153.56, 24896.32415
3) Octal & Hexadecimal Constants:
Example:
octal: (013 )8 = (11)10
Hexadecimal:(013)16 = (19)10
4) Character constants: ‘a’, ‘A’, ‘d’
5) String constants:
Example: “Freshersnow”
4) Operators
Operators in C++ are nothing but special symbols used for performing a particular task. They can perform mathematical (or) logical operations.
Different types of operators present in C++ are as follows:
- Arithmetic Operators
- Relational Operators
- Logical Operators
- Bitwise Operators
- Assignment Operator
- Unary operator
- Ternary or Conditional Operator
- Misc Operator
5) Strings
Strings are nothing but can be defined as a sequence of characters enclosed in double quotes, and includes letters, digits, special characters, and blank spaces. In strings, there is a difference between ” ” and ‘ ‘.
Syntax: datatype string;