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 - Choose the operator which cannot be overloaded.

A - /

B - ()

C - ::

D - %

Answer : C

Explaination

Scope resolution (::) is not permitted to be overloaded.

Q 2 - Which of the following is not the keyword in C++?

A - volatile

B - friend

C - extends

D - this

Answer : C

Explaination

All the rest are valid keywords of C++.

Answer : B

Explaination

Only members of the derived class and the same class can access a protected member.

Q 4 - Class function which is called automatically as soon as the object is created is called as __

A - Constructor

B - Destructor

C - Friend function

D - Inline function.

Answer : A

Explaination

If not provided the same, default constructor from the compiler is called automatically otherwise the programmers provided constructor gets called.

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;
void f() {
   cout<<"Hello"<<endl;
}
main() {
}

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<iostream>

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

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

#include<iostream>

using namespace std;
main() { 
   int r, x = 2;
   
   float y = 5;
  
   r = y%x;
   cout<<r; 
}

A - 1

B - 0

C - 2

D - Compile error

Answer : D

Explaination

Answer Compile Error, It is invalid that either of the operands for the modulus operator (%) is a real number.

#include<iostream>

using namespace std;
main() { 
   int r, x = 2;
   
   float y = 5;
  
   r = y%x;
   cout<<r; 
}

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() {
   char *s = "Fine";
	*s = 'N';
   
   cout<<s<<endl;
}

A - Fine

B - Nine

C - Compile error

D - Runtime error

Answer : D

Explaination

*s=N, trying to change the character at base address to N of a constant string leads to runtime error.

#include<iostream>

using namespace std;
main() {
   char *s = "Fine";
	*s = 'N';
   
   cout<<s<<endl;
}
cpp_questions_answers.htm
Advertisements