You are on page 1of 5

C++

1) How many arguments do destructors take?


a) Two
b) One
c) Any number of
d) None

2) When we pass arguments by reference, the formal arguments in the


called function become aliases to the actual arguments in the calling
function.
a) True
b) False

3) A constructor that accepts no parameters is called the ___________


a) Dynamic constructor
b) Parameterized constructor
c) Default constructor
d) None of the above

4) The last character in a string must be_________


a) 0 (Zero)
b) \0 (Null)
c) Empty
d) None of the above

5) A pure virtual function is a function that___________


a) has no body
b) returns nothing
c) is used in a base class
d) takes no arguments

6) A _______________ function can access a class private data, even


though it is not a member function of the class.
a) Friend
b) Static
c) Virtual
d) Abstract

7) What is the result of the following statement?

cout<<sizeof(float);
a) 4.000000
b) 2
c) 4
d) 8

8) What is the output of the following program?

#include<iostream.h>
void x(int a,int &b)
{
a=a+b;
a=a-b;
b=b-a;
}
void main()
{
int a=4,b=10;
x(a,b);
cout<<a<<b;
}

a) 4,10
b) 10,4
c) 4,4
d) 4,6

9) Which one of the following is a bitwise operator?


a) !
b) ~
c) ==
d) !=

10)What is the output of the following code?

int a=0;
for(int I=1;I<=a;I++)
cout<<I;

a) 0
b) 1
c) Nothing will get displayed
d) Error
11) Which one of the following is a valid method for accessing the 3rd element
of the array cust?
a) cust.3
b) cust[3]
c) cust[2]
d) cust(2)

12)Can class objects be passed to a function?


a) Yes
b) No

13)If p & q are int type variables, what will be the result of the expression

p%q
Where p=-16 and q=-3
a) 1
b) -1
c) 5
d) -5

14)Opening a file in ios::out mode also opens it in the __________ mode by


default.
a) ios::app
b) ios::in
c) ios::trunc
d) ios::nocreate

15)A function template definition begin with the keyword___________


a) template
b) class
c) namespace
d) class template

16)A constructor’s name is same as __________


a) Function name
b) Class name
c) Function name or class name
d) None of the above

17)Which manipulator is used to specify the required field size for displaying
an output value?

a) setfill()
b) setprecision()
c) setw()
d) setiosflags()

18)A pointer is a variable for storing


a) Integer values
b) Address of another variable
c) Its own address
d) None of the above

19)The default case is required in the switch selection structure.


a) Yes
b) No

20)The wrapping up of data & functions into a single unit is called


_____________
a) Inheritance
b) Abstraction
c) Polymorphism
d) Encapsulation

21)A c++ array can store values of different data types.


a) True
b) False

22)A datatype that allows different data types to be assigned to the same
storage location is called_________
a) Enum
b) Union
c) Array
d) None of the above

23)What is the value of a & b after the following two statements are
executed?

int a=10;
int b=a++ * ++a;

a) 132
b) 110
c) 120
d) None of the above
24)The following examples show that the class R id derived from classes P
and Q. Which of them are legal?
a) class R:public P: public Q
b) class R:public P,Q
c) class R:public P, public Q
d) class R::public P: public Q

25)Which one of the following is overloading the function?

int sum(int x,int y) {}

a) int sum(int x,int y,int z) {}


b) float sum(int x,int y) {}
c) int sum(int a,int b) {}
d) All of the above

ANSWERS

1. (d) None
2. (a) True
3. (c) Default constructor
4. (b) \0 null
5. (a) has no body
6. (a) Friend
7. (c) 4
8. (d) 4,6
9. (b) ~
10.(c) Nothing will get displayed
11.(c) cust[2]
12.(a) Yes
13.(b) –1
14.(c) ios::trunc
15.(a) template
16.(b) Class name
17.(c) setw()
18.(b) Address of another variable
19.(b) No
20.(d) Encapsulation
21.(b) False
22.(b) Union
23.(c) 120
24.(c) class R:public P, public Q
25.(a) int sum(int x,int y,int z) {}