C++ Test Questions Set 2

1)   Which of the following are true about static member function?

1. They can access non-static data members.
2. They can call only other static member functions.
3. They can access global functions and data.
4. They can have this pointer.
5. They cannot be declared as const or volatile.


a. Only 2
b. Only 2,5
c. Only 2,3,4,5
d. Only 2 , 3 , 5
e. All of these
Answer  Explanation 

ANSWER: Only 2 , 3 , 5

Explanation:
No explanation is available for this question!


2)   Static variable must be declared in public section of the class.

a. True
b. False


Answer  Explanation 

ANSWER: False

Explanation:
No explanation is available for this question!


3)   By default, if a function with minimum lines of code is declared and defined inside the class becomes Inline function.

a. True
b. False


Answer  Explanation 

ANSWER: True

Explanation:
No explanation is available for this question!


4)   class X, class Y and class Z are derived from class BASE. This is ______ inheritance.

a. Multiple
b. Multilevel
c. Hierarchical
d. Single
Answer  Explanation 

ANSWER: Hierarchical

Explanation:
No explanation is available for this question!


5)   When base class is derived in protected mode, then_____________ .

1. public members of base class become private members of derived class.
2. public members of base class become protected members of derived class.
3. public members of base class become public members of derived class.
4. protected members of base class become protected members of derived class.
5. protected members of base class become private members of derived class.
6. protected members of base class become public members of derived class.


a. Only 1, 5
b. Only 1, 6
c. Only 2, 6
d. Only 2, 4
Answer  Explanation 

ANSWER: Only 2, 4

Explanation:
No explanation is available for this question!


6)   Can we have overloading of the function templates?

a. Yes
b. No


Answer  Explanation 

ANSWER: Yes

Explanation:
No explanation is available for this question!


7)   Streams that will be performing both input and output operations must be declared as class _________ .

a. iostream
b. fstream
c. stdstream
d. Stdiostream
Answer  Explanation 

ANSWER: fstream

Explanation:
No explanation is available for this question!


8)   Exception handlers are declared with ____________ keyword.

a. Try
b. catch
c. throw
d. Finally
Answer  Explanation 

ANSWER: catch

Explanation:
No explanation is available for this question!


9)   Which of the following statements are true about Catch handler?

1. It must be placed immediately after try block T.
2. It can have multiple parameters.
3. There must be only one catch handler for every try block.
4. There can be multiple catch handler for a try block T.
5. Generic catch handler can be placed anywhere after try block.


a. Only 1, 4, 5
b. Only 1, 2, 3
c. Only 1, 4
d. Only 1, 2
Answer  Explanation 

ANSWER: Only 1, 4

Explanation:
No explanation is available for this question!


10)   Static variable declared in a class are also called_________ .

a. instance variable
b. named constant
c. global variable
d. class variable
Answer  Explanation 

ANSWER: class variable

Explanation:
No explanation is available for this question!


11)   Which of the following operator is used to release the dynamically allocated memory in CPP?

a. remove
b. free
c. delete
d. both b and c
Answer  Explanation 

ANSWER: delete

Explanation:
No explanation is available for this question!


12)   Which of the following is not a false statement about new operator?

a. It can’t be overloaded.
b. It returns garbage value when memory allocation fails.
c. It automatically computes the size of the data object.
d. All of these
Answer  Explanation 

ANSWER: It automatically computes the size of the data object.

Explanation:
No explanation is available for this question!


13)   Private members of the class are accessible only to the members of the same class.

a. True
b. False


Answer  Explanation 

ANSWER: False

Explanation:
No explanation is available for this question!


14)   Run time polymorphism can be achieved with______ .

a. Virtual Base class
b. Container class
c. Virtual function
d. Both a and c
Answer  Explanation 

ANSWER: Virtual function

Explanation:
No explanation is available for this question!


15)   To create an output stream, we must declare the stream to be of class ___________ .

a. ofstream
b. ifstream
c. iostream
d. None of these
Answer  Explanation 

ANSWER: ofstream

Explanation:
No explanation is available for this question!


16)   Catch handler can have multiple parameters.

a. True
b. False


Answer  Explanation 

ANSWER: False

Explanation:
No explanation is available for this question!


17)   Inline functions may not work ______ .

1. If function contain static variables.
2. If function contain global and register variables.
3. If function returning value consists looping construct(i.e. for, while).
4. If inline functions are recursive.
5. If function contains const value.


a. Only 1,4,5
b. Only 2,3,5
c. Only 1,3,4
d. All of these
Answer  Explanation 

ANSWER: Only 1,3,4

Explanation:
No explanation is available for this question!


18)   Which of the followings is/are not false about friend function ?

1. It can be called / invoked with class object.
2. It has objects as arguments.
3. It can have built-in types as arguments.
4. It must declared only in public part of a class.
5. It does not have this pointer as an argument.


a. Only 2,4
b. Only 1,2,5
c. Only 2,3,5
d. All of these
Answer  Explanation 

ANSWER: Only 2,3,5

Explanation:
No explanation is available for this question!


19)   Predict the output:

int x = 786;
cout << setfill(‘*’) << setw(6) << x;


a. 786***
b. **786
c. ***786
d. ******
Answer  Explanation 

ANSWER: ***786

Explanation:
No explanation is available for this question!


20)   Default return type of functions in CPP is ____ .

a. void
b. long
c. char
d. Int
Answer  Explanation 

ANSWER: Int

Explanation:
No explanation is available for this question!


21)   Default values for a function are need to be specified from left to right only.

a. True
b. False


Answer  Explanation 

ANSWER: False

Explanation:
No explanation is available for this question!


22)   During a class inheritance in CPP, if the visibility mode or mode of derivation is not provided, then by default visibility mode is  ___________.

a. public
b. protected
c. private
d. Friend
Answer  Explanation 

ANSWER: private

Explanation:
No explanation is available for this question!


23)   The derivation of Child class from Base class is indicated by ____ symbol.

a. ::
b. :
c. ;
d. |
Answer  Explanation 

ANSWER: :

Explanation:
No explanation is available for this question!


24)   If we have object from fstream class, then what is the default mode of opening the file?

a. ios::in|ios::out
b. ios::in|ios::out|ios::trunc
c. ios::in|ios::trunc
d. Default mode depends on compiler
Answer  Explanation 

ANSWER: Default mode depends on compiler

Explanation:
No explanation is available for this question!


25)   __________ is return type of is_open() function.

a. int
b. bool
c. float
d. char *
Answer  Explanation 

ANSWER: bool

Explanation:
No explanation is available for this question!