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

Answer : B

Explaination

It is sufficient to have one pure virtual function in the class to make it as an abstract class.

Answer : B

Explaination

Its an object of istream class.

Q 3 - The following operator can be used to calculate the value of one number raised to another.

A - ^

B - **

C - ^^

D -None of the above

Answer : D

Explaination

There is no such operator in C/C++.

Q 4 - We can use this pointer in static member function of the class.

A - True

B - False

Answer : B

Explaination

False, as the static members do exist before the object of the respective class are created. 'this' is not applicable in the said context.

Q 5 - Which operator is used to resolve the scope of the global variable?

A - −>

B - .

C - *

D - ::

Answer : D

Explaination

Scope resolution operator is used to resolve for the global scope of a variable if the local and global variables conflict by name.

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

using namespace std;
void f() {
   cout<<"Hello"<

A - No output

B - Error, as the function is not called.

C - Error, as the function is defined without its declaration

D - Error, as the main() function is left empty

Answer : A

Explaination

No output, apart from the option (a) rest of the comments against the options are invalid

#include

using namespace std;
void f() {
	cout<<"Hello"<

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

#include

using namespace std;
void swap(int m, int n) {
   int x = m;

	m = n;
	n = x;
}
main() {
   int x = 5, y = 3;
   
	swap(x,y);
	cout<

A - 3 5

B - 5 3

C - 5 5

D - Compile error

Answer : B

Explaination

5 3, call by value mechanism cant alter actual arguments.

#include

using namespace std;
void swap(int m, int n) {
   int x = m;

	m = n;
	n = x;
}
main() {
   int x = 5, y = 3;
   
	swap(x,y);
	cout<

Q 9 - An inline function can execute faster than a normal function.

A - True

B - False

Answer : A

Explaination

As the code of inline function gets expanded at the line of call, therefore it gets executed faster with no overhead of context switch

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

#include
#include

using namespace std;
main() { 
   char s[] = "Hello\0Hi";
   
   cout<

A - 5 9

B - 7 20

C - 5 20

D - 8 20

Answer : A

Explaination

Length of the string is count of character upto \0. sizeof reports the size of the array.

#include
#include

using namespace std;
main() { 
   char s[] = "Hello\0Hi";
   
   cout<
cpp_questions_answers.htm
Advertisements