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 - A trigraph character begins with

A - #

B - ##

C - ?

D - ??

Answer : C

Explaination

Few characters have alternative representation and start with ??. Eg. Fro [ equivalent is ??(

Q 2 - Choose the respective delete operator usage for the expression ‘ptr=new int[100]’.

A - delete ptr;

B - delete ptr[];

C - delete[] ptr;

D - []delete ptr;

Answer : C

Explaination

Answer : C

Explaination

Virtual functions gives the ability to override the functionality of base class into the derived class. Hence achieving dynamic/runtime polymorphism.

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 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() { 
   static int i; 
   
   ++i; 
   cout<<i<<" "; 
}

main() { 
   f(); 
   f(); 
   f(); 
}

A - 1 1 1

B - 0 0 0

C - 3 2 1

D - 1 2 3

Answer : D

Explaination

1 2 3, A static local variables retains its value between the function calls and the default value is 0.

#include<iostream>

using namespace std;
void f() { 
   static int i; 
   
   ++i; 
   cout<<i<<" "; 
}

main() { 
   f(); 
   f(); 
   f(); 
}

Q 8 - What is the size of the following union definition?

#include<iostream>

using namespace std;
main() {
   union abc { 
      char a, b, c, d, e, f, g, h; 
      
      int i;
   };
   cout<<sizeof(abc);
}

A - 1

B - 2

C - 4

D - 8

Answer : C

Explaination

union size is biggest element size of it. All the elements of the union share common memory.

#include<iostream>

using namespace std;
main() {
   union abc { 
      char a, b, c, d, e, f, g, h; 
      
      int i;
   };
   cout<<sizeof(abc);
}

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 - i) Exceptions can be traced and controlled using conditional statements.

ii) For critical exceptions compiler provides the handler

A - Only (i) is true

B - Only (ii) is true

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

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

Answer : B

Explaination

Conditional statements are used to take alternate actions depending upon certain condition but not multi branching. C++ too provides some critical exception handlers.


cpp_questions_answers.htm

Advertisements