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 - ‘cin’ is an __

A - Class

B - Object

C - Package

D - Namespace

Answer : B

Explaination

It’s an object of istream class.

Answer : B

Explaination

Both the mentioned operators cannot be overloaded.

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 - 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 - i) single file can be opened by several streams simultaneously.

ii) several files simultaneously can be opened by a single stream

A - (i) and (ii) are true

B - (i) and (ii) are false

C - Only (i) is true

D - Only (ii) is true

Answer : C

Explaination

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

#include <iostream>
using namespace std;
 
int main () {
   // local variable declaration:
   int x = 1;

   switch(x) {
   case 1 :
      cout << "Hi!" << endl; 
      break;
   default :
      cout << "Hello!" << endl;
   }
}

A - Hello

B - Hi

C - HelloHi

D - Compile error

Answer : B

Explaination

Hi, control reaches default-case after comparing the rest of case constants.

#include <iostream>
using namespace std;
 
int main () {
   // local variable declaration:
   int x = 1;

   switch(x) {
   case 1 :
      cout << "Hi!" << endl; 
      break;
   default :
      cout << "Hello!" << endl;
   }
}

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

#include<iostream>

using namespace std;
main() { 
   int i = 13, j = 60;
   
   i^=j;
   j^=i;
   i^=j;
   cout<<i<<" "<<j;
}

A - 73 73

B - 60 13

C - 13 60

D - 60 60

Answer : B

Explaination

60 13, its swapping.

#include<iostream>

using namespace std;
main() { 
   int i = 13, j = 60;
   
   i^=j;
   j^=i;
   i^=j;
   cout<<i<<" "<<j;
}

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