-1.2 C
New York
Thursday, March 4, 2021
Home Website & Development 6 Types of Tokens in C++ programming

6 Types of Tokens in C++ programming

The smallest unit of a program in C ++ is called a tokens.

A token is a group of characters that logically belong together. The programmer can write a program using tokens.


  1. Types of tokens in c++ programming
  2. Keywords
  3. Operators
  4. Strings
  5. Constants
  6. Identifiers
  7. Special characters
  8. Conclusion
  9. Frequently asked questions

Types of tokens in c++ programming

the smallest unit of a program in C ++ is called a token.

1. Keywords –

These are some reserved words in C++ which have predefined meaning to compiler called keywords.

The reserved words of C ++ language by which we use Programming are called Keyword. All keywords are written in Small Letters and are of the same word.

They are known as Reserve Words. C ++ has 48 keywords and most of the keywords have C programming. Some new Keywords added to OOP. Some commonly used Keyword are given below –


2. Operators –

these are special symbols used for specific purposes.  that perform some arithmetical and logical tasks after being applied to any of the variables or objects.

Operators need data or operands to perform. you are writing a + b the addition is being performed a and b are operands which will have some value and there is + operator which is telling the compiler that addition operation is over here to perform.

The signs , used Variables, act on them, are called Operators.

C ++ has different types of operators.

knowing about operators, we need to know what is Expression, Expression is an expression or Expression, an Operand, an Operator, and a group of two small cells and the Operand is a constant. are variable or number

Like = (A + B) is an expression.This marked or denominated constant or variable is an expression.

Now we will know how many types of operators there are, to divide the operators we can do the number of operands used in it.

operators in c++

1. Unary Operator –

Unary operators are called operators who perform tasks with single operand as increment decrement operators. Ex: a++, a–, ++aa,–a

Increment / Decrement Operator

2. Binary Operators –

Binary operators are called such operators who need two operands to perform the task. Such as: Arithmetic operator (+, -, *, /), Relational Operator (>, <,> =, <=) etc.

Types of Binary Operators

  • Arithmetic Operators
  • Relational Operators
  • Logical Operators
  • Assignment Operators
  • Bitwise Operators

3. Ternary Operator –

Ternary operators are called such operators who require three operands. It is used in decision making. Like <condition>? <true block>: <false block>;

  • Conditional Operators

3. Strings –

string in c++

The final character of string is ‘NULL’ (\ 0).

This is a one-dimensional array, which contains only characters.

Strings are a group of characters.

If the entire string is to be written, it is written in double quotes (“”).

If each character is to be written, it is written in single quotes (”).

A String has a data type of character (char).

Each String in the program has a different size in the initialization.

The memory of the size of the given array is allocated. If the size of the Array is not given, the size array allocates as much size as the string.

To use these functions in the program, #include<string.h> or #include<strings.h> have to include these header file.

Types of strings

Strcat- is added from one string to other string.

Strchr- Returns the pointer to the string next to the first element of a character from the given string.

Strcmp- compares two strings. It is case-sensitive.

Strcmpi- Two string is compared. It is not case-sensitive.

Strcpy- copies one string to other string.

Strdup- duplicates String.

Strlen- String Length is derived.

Strlwr- Uppercase is converted to lowercase.

Strncat- String is added to as many characters as the given number.

Strncpy- The number of characters of a given number is copied from one string to other string.

Strnset- replaces string according to a given number and a given character.

Strrchr- returns a string pointer to the string of a character from the string.

Strrev- prints the string in the opposite direction.

Strrstr- returns the pointer to the next string preceding the string of the given string.

Strset- replaces the entire string with the given character.

Strstr- returns the string pointer next to the first string of the given string.

Strupr- the lowercase are converted to Uppercase.

Example –

/* C++ Strings – Example Program of C++ Strings */
void main()
            char str[30];//character string
            cout<<“Enter your name: “;
            cout<<“namaste, “<<str;

Output –

string output

4. Constants –

A constant, like a variable, is a memory location where a value can be stored. variables, constants never change in value. You must initialize a constant it is created.

Constant is declared with a const keyword whose value never changes in the execution of the program. The Fixed value is known as literals.

Constants in c++

Example –

void main()
            const int number=909;
            cout<<“The constant integer value is “<<number;

Output –

constants output

5. Identifiers –

Variable, Function, Array, and Classes are the names created by a program. Symbolic names can be used in C++ for various data items used by a programmer in his program.

A symbolic name is a known identifier. The identifier is a sequence of characters taken from the C++ character set.


The rule for the formation of an identifier is

An identifier can consist of alphabets, digits, and/or underscores.

Their names do not begin with numbers.

There should be no space between their names.

No keywords in their names are used.

It should not be a reserved word.

C++ is case sensitive is upper case and lower case letters are considered separate from each other.

Example –

/* C++ Identifiers Example */
void main()
         clrscr();//clear screen
       char cc;        // here cc is an identifier
       char name[20];  // here name is an identifier
       int no;        // here no is an identifier
       cout<<“Enter a character : “;
       cout<<“You entered “<<cc;
       cout<<“\nEnter your name : “;
       cout<<“Your name is “<<name;
       cout<<“\nEnter a number : “;
       cout<<“You entered “<<no;

Output –

identifier output

read also – storage-classes

6. Special characters

The Compiler has a special meaning of special symbol meaning all special

The symbol has a different definition. It is used to perform special tasks.

Square brackets [], curly braces {}, parentheses (),

semicolon (;), comma (,) are all special symbols.

Special characters

Brackets [ ] – Opening Brackets and closing brackets are used to define an array element.

Example: int arr [9];

Curly braces { } – Curly braces are used to define the scope of a block. As you can see in the program given above, after the main () function, the curly braces are opened and in the end, the curly braces are closed

Example: the farther away its curly braces are open and closed. Is the scope of main() function.

parenthesis ( ) – Parenthesis is used to identify a function. We can send parameters inside the parenthesis. Example: main ()

Semicolon (;) – Semicolon is a terminator used to terminate a line.

Comma (,) Comma is a separator is used to separate statement. ex-initialization, test condition, and increment/decrement are separated by a comma in for loop.

Asterisk (*) This is a special symbol is used to create pointer variables. Like int * a;

source – tutorialspoint

Conclusion –

Types of tokens – keywords, Operators, strings, special symbols, constants, Identifiers. all of them Syntax, examples, outputs I gave you above.

Friends, reading this post completely, you must have understood tokens in c++ programming. you must have liked it. I try to describe to you in simple language, maybe you must have understood it in this post. I have covered Topics you do not need to read any other post. If you liked this article, then definitely share it with your friends. And there is some doubt. Then comment I will definitely answer your comment.

Frequently asked questions

1. What are tokens?

Tokens are the smallest unit of a program

2. Types of tokens?

Identifiers, Keywords, Constant, Strings, Operators, Special symbols.

3. What are keywords?

These are some reserved words in C++ which have predefined meaning to compiler called keywords

4. How many keywords in c++?

48 keywords in c++

5. What are Identifiers?

A symbolic name is a known identifier. The identifier is a sequence of characters taken from the C++ character set.

6. Rule of Identifiers?

An identifier can consist of alphabets, letters, and digits, and/or underscores.

7. What is Literals?

Literals (often referred to as constants) are data items that never change their value the execution of the program.

8. What is the string?

a group of characters known as string.

9. How to connect two strings in the c++ program?

Strcat()    This is a function of String. One string is connected to other string.

10. What is strlen()?

This is a normal string whose length is derived.

11. What is strdup()?

This is the string whose duplicate is made.

12. What is Operators?

Operators are special symbols used for specific purposes.

13. What is a special symbol

Each special symbol has a specific meaning to the C++ compiler.


Please enter your comment!
Please enter your name here

Most Popular

How is Sabudana made in India? Complete Process

How is Sabudana made in India? Sabudana or Sago in English is the most favourite food of Indians. It is widely consumed...

A Guide to Know Everything About ESG Metrics

ESG metrics criteria are an increasingly popular way for investors to evaluate companies they might want to invest in. Environment, Social and...

Best Smartwatches in 2021 – Smartwatch Buying Guide in Detail

Do you have a smartwatch or are you planning to buy a smartwatch? If you are wondering about a wristwatch that only...

Detailed Guide to Buy Best Laptops Under 45000 in India

Nowadays, whether you are student, office going person, businessman or a freelancer, Laptops are the necessity for your day to day tasks...

Recent Comments