Getting Started With C++
(Sumita Arora) Textbook Solutions 7th Edn
credits:openclipart |
SHORT ANSWER QUESTIONS
Q1: What are tokens in C++? How many types of tokens allowed in C++? Exemplify your answer.Answer: A token is the smallest unit of a c++ program that can be processed by a c++ compiler. These are also called lexical units or lexical elements. C++ has the following tokens:
- Keywords: Reserved words which have special meaning or purpose. e.g. for, const, while, class, struct etc.
- Identifiers: These are the names given to variables, constants, arrays, functions, classes or objects of a c++ program. Identifiers are case sensitive in c++. e.g. valid identifiers are: student, Date123, file234 etc.
- Literals: Data Items that never change their value during program run. Also called constants. In C++ there are five types of literals i.e. bool literal, integer constants, character constants, floating constants and string literals. e.g. 1234, 'b', 3.14 etc.
- Punctuators: These are tokens which have syntactic and semantic meaning to the compiler. e.g. {}, =, ++, -, %, *= etc.
- Operators: These are the tokens that tell the c++ compiler to perform specific mathematical or logical manipulations. C++ is full of operators. e.g. Arithmetic operators(+,-,*,/,%), Shift operators(<<. >>), Bitwise operators(&, ^, |), logical operators(&&, ||) etc.