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.

Q 2 - A user defined header file is included by following statement in general.

A - #include “file.h”

B - #include <file.h>

C - #include <file>

D - #include file.h

Answer : A

Explaination

With the syntax as in (a) the compiler first looks for the file in the present working directory and then in the default include path if not found.

Q 3 - Pick up the valid declaration for overloading ++ in postfix form where T is the class name.

A - T operator++();

B - T operator++(int);

C - T& operator++();

D - T& operator++(int);

Answer : B

Explaination

The parameter int is just to signify that it is the postfix form overloaded. Shouldn’t return reference as per its original behavior.

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 programmer’s provided constructor gets called.

Q 5 - Which feature of the OOPS gives the concept of reusability?

A - Abstraction

B - Encapsulation

C - Inheritance

D - None of the above.

Answer : C

Explaination

The process of designing a new class (derived) from the existing (base) class to acquire the attributes of the existing is called as inheritance. Inheritance gives the concept of reusability for code/software components.

Answer : B

Explaination

Defining a templated class is defining a generic class. Hence functionality of the class is generalized for several types, if applicable.

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

#include<iostream>

using namespace std;
main() {
   short unsigned int i = 0; 
   
   cout<<i--;
}

A - 0

B - Compile error

C - 65535

D - 32767

Answer : A

Explaination

0, with post decrement operator value of the variable will be considered as the expression’s value and later gets decremented

#include<iostream>

using namespace std;
main() {
   short unsigned int i = 0; 
   
   cout<<i--;
}

Q 8 - What is the size of ‘int’?

A - 2

B - 4

C - 8

D - Compiler dependent

Answer : D

Explaination

The size of ‘int’ depends upon the complier i.e. whether it is a 16 bit or 32 bit.

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

#include<iostream>

using namespace std;
int x = 5;

int &f() {
	return x;
}
main() {
	f() = 10;
   cout<<x;
}

A - 5

B - Address of ‘x’

C - Compile error

D - 10

Answer : D

Explaination

A function can return reference, hence it can appear on the left hand side of the assignment operator.

#include<iostream>

using namespace std;
int x = 5;

int &f() {
	return x;
}
main() {
	f() = 10;
   cout<<x;
}

Q 10 - What is the built in library function to compare two strings?

A - string_cmp()

B - strcmp()

C - equals()

D - str_compare()

Answer : B

Explaination

strcmp() is the built in function from “string.h” to compare two strings. Returns 0 if both are same strings. Returns -1 if first < second string. Returns 1 first > second.

cpp_questions_answers.htm
Advertisements