11th Computer Science 12th Computer Science BCA CBSE CBSE JAC JAC

Tokens in C++ Programming Language

Tokens in C++ Programming Language
Written by AIPS

The smallest individual unit of C++ program is called tokens.

A C++ program is made up of various tokens.

There are following types of tokens:

  1. Keywords / Reserve words
  2. Identifiers / Variables
  3. Constants/ Literals
  4. Operators
  5. Separators / Punctuators / special characters

1.Keywords

Keywords have fixed meaning and these meaning can’t be changed.

Keywords are reserve words for the system, so these are also known as reserve words.

These are the special words that has special importance and significance.

There are 63 keywords in C++.

These can’t be used as user defined name like variable name, array name , function name, class name , etc…

Example : char, int , float, long, double, void , if , else, break, switch, for, while , do, class, struct, union ,

2. Identifier

Meaningful variable name, array name, function name, class name, etc.. known as Identifier.

An identifier is a user defined word.

Variable:– it is a data name used to store data value.

it is like a container of data.

Rules for declaring variable:

  • The variable name must begin with character without space but underscore is permitted.
  • The variable name should not start with a digit.
  • The variable name should not be a C++ keywords.
  • The variable name may be a combination of uppercase and lowercase character.
  • The length of variable may up to 31 characters.
  • Special characters or symbols not allowed between variable name.

3.Constant :- It refers to fixed value and the value can’t be changed during the program execution.

we use const keyword or #define for declaring constant.

Example

const float pi=3.14;

#define pi 3.14

There are two types of constants.

  1. Numeric constant
    • a. Integer constant ex.. 5, -17,
    • b. Real constant ex.. 12.6 , -18.5
  2. Character constant
    • a. Single character ex.. ‘5’ ‘Á’
    • b. String constant ex. “528” “Ram”

4. Operator

An operator is a symbol that represent operation between operands.

An operator is a symbol that perform operations(such as addition, subtraction,multiplication,division etc) on various data items(operands) to produce result.

C=a+b

Here a,b,c are operands, and + and = are operators

5. Separators :- These define structure of a program.

example {} ,[],(), etc

Also Read : – Translators in C++ Language

Also Read :- Previous year Question & important program

About the author

AIPS

Leave a Comment