C++ Online Quiz


Advertisements

Following quiz provides Multiple Choice Questions (MCQs) related to C++ Framework. You will have to read all the given answers and click over the correct answer. If you are not sure about the answer then you can check the answer using Show Answer button. You can use Next Quiz button to check new set of questions in the quiz.

Questions and Answers

Q 1 - Choose the pure virtual function definition from the following.

A - virtual void f()=0 { }

B - void virtual f()=0 { }

C - virtual void f() {} = 0;

D - None of the above.

Answer : D

Explaination

A pure virtual function cannot have a definition.

Q 2 - From the below class choose the proper definition of the member function f().

template <class T>

class abc {
   void f();
};

A - template <class T>

    void abc<T>::f() { }

B - template<class T>

    void abc::f() { }

C - template<T>

    void abc<class T>::f() { }

D - template<T>

    void abc<T>::f() { }

Answer : A

Explaination

Q 3 - Which is the storage specifier used to modify the member variable even though the class object is a constant object?

A - auto

B - register

C - static

D - mutable

Answer : D

Explaination

mutable is storage specifier introduced in C++ which is not available in C. A class member declared with mutable is modifiable though the object is constant.

Q 4 - Escape sequence character '\0' occupies __ amount of memory.

A - 0

B - 1

C - 2

D - 4

Answer : B

Explaination

As it is also a character is occupies 1 byte of memory.

Q 5 - Which feature of the OOPS gives the concept of reusability?

A - Abstraction

B - Encapsulation

C - Inheritance

D - None of the above.

Answer : C

Explaination

The process of designing a new class (derived) from the existing (base) class to acquire the attributes of the existing is called as inheritance. Inheritance gives the concept of reusability for code/software components.

Q 6 - A C++ program statements can be commented using

A - Single line comment

B - Multi line comment

C - Either (a) or (b)

D - Both (a) and (b).

Answer : D

Explaination

Both styles of commenting is available in C++.

Answer : A

Explaination

When the program is in execution phase the possible unavoidable error is called as an exception.

Q 8 - What is the output of the following program?

#include<iostream>

using namespace std;
main() { 
   float t = 2;
	
	switch(t) {
      case 2: cout<<”Hi”;
		default: cout<<"Hello";
	}
}

A - Hi

B - HiHello

C - Hello

D - Error

Answer : D

Explaination

Error, switch expression can’t be float value

#include<iostream>

using namespace std;
main() { 
   float t = 2;
	
	switch(t) {
		case 2: cout<<”Hi”;
		default: cout<<"Hello";
	}
}

Q 9 - Following is the invalid inclusion of a file to the current program. Identify it

A - #include <file>

B - #include "file"

C - #include < file

D - All of the above are invalid

Answer : C

Explaination

option (a) & (b) are valid. There is no such syntax or provision as in option (c).

Q 10 - i) Exceptions can be traced and controlled using conditional statements.

ii) For critical exceptions compiler provides the handler

A - Only (i) is true

B - Only (ii) is true

C - Both (i) & (ii) are true

D - Both (i) && (ii) are false

Answer : B

Explaination

Conditional statements are used to take alternate actions depending upon certain condition but not multi branching. C++ too provides some critical exception handlers.

cpp_questions_answers.htm
Advertisements