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 - What is the output of the following program?

#include<iostream>

using namespace std;
main() { 

   int i = 1, j = 2, k = 3, r; 

   r = (i, j, k);

   cout<<r<<endl;

}

A - 1

B - 2

C - 3

D - Compile Error

Answer : C

Explaination

Comma is called as the separator operator and the associativity is from left to right. Therefore k is the expressions resultant.

#include<iostream>

using namespace std;
main() { 

   int i = 1, j = 2, k = 3, r; 

   r = (i, j, k);

   cout<<r<<endl;

}

Q 4 - How many number of arguments can a destructor of a class receives?

A - 0

B - 1

C - 2

D - None of the above.

Answer : A

Explaination

The destructor receives no arguments and is only form to be provided. Hence destructor cannot be overloaded.

Q 5 - The programs machine instructions are store in __ memory segment.

A - Data

B - Stack

C - Heap

D - Code

Answer : D

Explaination

Code segments holds the program instructions and fetched by instruction pointer for execution.

Q 6 - Which type of data file is analogous to an audio cassette tape?

A - Random access file

B - Sequential access file

C - Binary file

D - Source code file

Answer : B

Explaination

As the access is linear.

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

#include<iostream>

using namespace std;
main() { 
   const int a = 5;
   
   a++; 
   cout<<a; 
}

A - 5

B - 6

C - Runtime error

D - Compile error

Answer : D

Explaination

Compile error - constant variable cannot be modified.

#include<iostream>

using namespace std;
main() { 
   const int a = 5;
   
   a++; 
   cout<<a; 
}

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 cant be float value

#include<iostream>

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

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;
void main() {
   char *s = "C++";
   
	cout<<s<<" ";
	s++;
	cout<<s<<" ";
}

A - C++ C++

B - C++ ++

C - ++ ++

D - Compile error

Answer : B

Explaination

After s++, s points the string ++.

#include<iostream>

using namespace std;
void main() {
   char *s = "C++";
   
	cout<<s<<" ";
	s++;
	cout<<s<<" ";
}
cpp_questions_answers.htm
Advertisements