C++ Online Quiz



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 - A constructor can be virtual.

A - True

B - False

Answer : B

Explaination

The purpose of the constructor cannot be overridden in the derived class hence constructor cannot be a virtual.

Q 2 - Which operator is required to be overloaded as member function only?

A - _

B - _ _

C - ++ (postfix version)

D - =

Answer : D

Explaination

Overloaded assignment operator does the job similar to copy constructor and is required to be overloaded as member function of the class.

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 - The pointer which stores always the current active object address is __

A - auto_ptr

B - this

C - p

D - none of the above.

Answer : B

Explaination

this is the keyword and acts as a pointer which always holds current active objects.

Q 6 - (i) ‘ios’ is the base class of ‘istream’

(ii) All the files are classified into only 2 types. (1) Text Files (2) Binary Files.

A - Only (i) is true

B - Only (ii) is true

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

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

Answer : C

Explaination

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

#include<iostream>

using namespace std;
main() {
   char s[] = "hello", t[] = "hello";
   if(s==t)
      cout<<"eqaul strings";
}

A - Equal strings

B - Unequal strings

C - No output

D - Compilation error

Answer : C

Explaination

No output, as we are comparing both base addresses and are not same.

#include<iostream>

using namespace std;
main() {
   char s[] = "hello", t[] = "hello";
   if(s==t)
      cout<<"eqaul strings";
}

Q 8 - What is the size of ‘int’?

A - 2

B - 4

C - 8

D - Compiler dependent

Answer : D

Explaination

The size of ‘int’ depends upon the complier i.e. whether it is a 16 bit or 32 bit.

Q 9 - Identify the C++ compiler of Linux

A - cpp

B - g++

C - Borland

D - vc++

Answer : B

Explaination

g++ is GNU C++ compiler for linux. Borland and vc++ (Microsoft visual c++) for windows.

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

#include<iostream>

using namespace std;
main() { 
   class student { 
      int rno = 10;
   } v;
  
   cout<<v.rno;
}

A - 10

B - Garbage

C - Runtime error

D - Compile error

Answer : D

Explaination

Class member variables cannot be initialized.

#include<iostream>

using namespace std;
main() { 
   class student { 
      int rno = 10;
   } v;
  
   cout<<v.rno;
}
cpp_questions_answers.htm
Advertisements