0% found this document useful (0 votes)
10 views3 pages

Revision Questions For C++

Revision questions for c++

Uploaded by

shrutishewale880
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views3 pages

Revision Questions For C++

Revision questions for c++

Uploaded by

shrutishewale880
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

2.

C++ - Introduction
Answer the following questions:

1. What are tokens?


Ans: Tokens are the smallest individual units of a program.
Following are the C++ tokens :
● Keywords
● Identifiers
● Constants
● Variables
● Operators

2. What are the types of tokens in C++?


Ans: Following are the C++ tokens :
● Keywords
● Identifiers
● Constants
● Variables
● Operators

3. What is a variable? Give an example.

Ans: A variable definition tells the compiler where and how much storage

to create for the variable. A variable definition specifies a data type,

and contains a list of one or more variables of that type as follows −

Syntax for declaration:

type variable_list;

Some valid declarations are shown here −

int i, j, k;

char c, ch;

float f, salary;

double d;

4. What is a constant? Give an example.

Ans: Constants are like a variable, except that their value never changes during execution once
defined.

Declaration of a constant :

Syntax:
const [data_type] [constant_name]=[value];

5. What are keywords? List a few of them in C++.

Ans: Keywords are reserved words which have fixed meaning, and its meaning cannot be changed.

C++ has more keywords than C, and those extra ones have special working capabilities.

Eg: class, const, etc

6. What are operators?

Ans: C++ operator is a symbol that is used to perform mathematical or logical manipulations.

● Arithmetic Operators

● Increment and Decrement Operators

● Relational Operators

● Logical Operators

● Bitwise Operators

● Assignment Operators

● Misc Operators

3. Write the difference between % and / operator.

Ans: % Modulus Operator


Divides numerator by
Denominator. Give
remainder as a result after an
integer division.
Eg.int A=2,B=4;
B % A will give 0

/ Divide operator
Divides numerator by
Denominator . Give quotient as a result.
Eg. Int A=2,B=4;
B / A will give 2

4. Write the difference between = and ==.


Ans: The '=' is the so-called assignment operator and is used to assign the result of the
expression on the right side of the operator to the variable on the left side.
The '==' is the so-called equality comparison operator and is used to check whether the two
expressions on both sides are equal or not.

5. Write the difference between // and /*...*/.


Ans: C++ supports single-line and multi-line comments. All characters
available inside any comment are ignored by C++ compiler.
// starts a comment that extends to the end of the line.
/*… */ encloses a comment that can be anywhere inside of a line or spanning across a block
of lines.

6. What is a namespace?
Ans: A namespace is designed to overcome this difficulty and is used as additional
information to differentiate similar functions, classes, variables etc. with the same name
available in different libraries. Using namespace, you can define the context in which names
are defined. In essence, a namespace defines a scope.
A namespace definition begins with the keyword namespace followed by the namespace
name as follows −
namespace namespace_name {
// code declarations
}
To call the namespace-enabled version of either function or variable, prepend (::) the
namespace name as follows −
name::code; // code could be variable or function.

************

You might also like