Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

101.

How many types of guarantees are there in exception class can have?(a) 1(b) 2(c) 3(d) 4This question was addressed to me in semester exam.Origin of the question is Class Hierarchies Introduction topic in portion Class Hierarchies, Library & Containers of C++

Answer» RIGHT option is (C) 3

To explain I would say: There are three types of guarantees in c++. They are WEAK, STRONG and no-throw.
102.

In which of the following relationship objects of related classes can occur independently?(a) Aggregation(b) Association(c) Composition(d) Both Aggregation an AssociationI had been asked this question in an online quiz.Query is from Class Relationships topic in division Class Hierarchies, Library & Containers of C++

Answer»

The CORRECT option is (d) Both Aggregation an ASSOCIATION

The explanation is: In both Aggregations and Association of objects of related classes can occur INDEPENDENTLY. For example, an employee can have a bank and a bank can have an employee. Also, Association is a superset of Aggregation, THEREFORE, it also follows the same.

103.

Which of the following relationships is uni-directional?(a) Aggregation(b) Association(c) Composition(d) Both Aggregation and CompositionI got this question in an internship interview.My question comes from Class Relationships topic in chapter Class Hierarchies, Library & Containers of C++

Answer»

Correct answer is (d) Both AGGREGATION and COMPOSITION

The BEST EXPLANATION: Both Association and composition are uni-directional relationships. For example, departments can have STUDENTS but another way around is not possible.

104.

What is a Random number generator?(a) A generator that generates deterministic random numbers(b) A generator that generates both non-deterministic random numbers and deterministic random numbers(c) A generator that generates non-deterministic random numbers(d) A generator that generates a simple random numberI had been asked this question by my college director while I was bunking the class.My question comes from Generators in section Class Hierarchies, Library & Containers of C++

Answer» CORRECT option is (c) A GENERATOR that generates non-deterministic RANDOM NUMBERS

Best explanation: Random number generator is a random number generator which generates non-deterministic random numbers.
105.

What is linear_congruential_engine?(a) Pseudo-random number engine that generates random unsigned integers in the range [0, 2^w-1] for some w using Mersenne Twister algorithm(b) Pseudo-random number engine that generates random unsigned integers(c) Pseudo-random number engine that generates random unsigned integers in the range [0, 2^w-1] for some w using lagged Fibonacci generator(d) Pseudo-random number engine that generates random signed integers in the range [0, 2^w-1] for some w using Mersenne Twister algorithmI had been asked this question by my college professor while I was bunking the class.This interesting question is from Generators topic in portion Class Hierarchies, Library & Containers of C++

Answer»

Correct answer is (b) Pseudo-RANDOM NUMBER engine that GENERATES random unsigned integers

For explanation: linear_congruential_engine is a SIMPLE Pseudo-random number engine that generates random unsigned integer using the basic algorithm.

106.

What are the Generators in C++?(a) An object that generates uniformly distributed numbers(b) An object that generates a number from a given sequence(c) An object that generates the smallest number from a given range(d) An object that generates unique numbersThe question was posed to me in examination.The doubt is from Generators topic in division Class Hierarchies, Library & Containers of C++

Answer»

Right OPTION is (a) An OBJECT that generates UNIFORMLY distributed numbers

The EXPLANATION: Generators are objects that generates uniformly distributed numbers which HELP in generating random numbers.

107.

What type of class template is list?(a) Class-based(b) Node-based(c) Method-based(d) size-basedI got this question in an online interview.This is a very interesting question from Almost Containers topic in portion Class Hierarchies, Library & Containers of C++

Answer» CORRECT answer is (b) Node-based

For explanation: It is node-based because it allows for efficient INSERTION ANYWHERE in the PROGRAM.
108.

Pick out parameter for rehash method in unordered_set in c++?(a) count(b) size(c) hash(d) typeThe question was posed to me in an internship interview.My doubt is from Standard Library Design topic in division Class Hierarchies, Library & Containers of C++

Answer»

Correct option is (a) count

To explain I WOULD say: count is used to RETURN the NEW number of BUCKETS.

109.

What must be an operand of operator delete?(a) Pointer(b) Array(c) Stack(d) QueueThe question was posed to me by my college professor while I was bunking the class.I want to ask this question from Free Store topic in portion Class Hierarchies, Library & Containers of C++

Answer» CORRECT option is (a) POINTER

Easiest explanation - The operand of delete MUST be a pointer RETURNED by NEW.
110.

What type of class member is operator new?(a) static(b) dynamic(c) const(d) smartThe question was asked in a national level competition.Asked question is from Free Store in section Class Hierarchies, Library & Containers of C++

Answer» CORRECT answer is (a) STATIC

Explanation: static is a type of CLASS member is operator NEW.
111.

Which access specifier is used where one wants data members to be accessed by other classes but not from outside objects?(a) private(b) protected(c) public(d) both protected and publicThis question was posed to me in quiz.Enquiry is from Access Control in division Class Hierarchies, Library & Containers of C++

Answer»

The correct CHOICE is (B) protected

The best explanation: Protected and public members are ACCESSIBLE from derived classes but public members can be ACCESSED by objects of the class so protected specifier is the answer.

112.

The concept of deciding which function to invoke during runtime is called ______________________(a) late binding(b) dynamic linkage(c) static binding(d) both late binding and dynamic linkageThe question was posed to me in an interview.Enquiry is from Inheritance topic in portion Class Hierarchies, Library & Containers of C++

Answer»

Right OPTION is (d) both LATE BINDING and dynamic linkage

To explain I would say: The concept of deciding which function to invoke during runtime is called late binding or dynamic linkage. Late binding because function binding to the OBJECT is done during runtime. Dynamic linkage because this binding is done during runtime.

113.

Which of the following is corect way of constructing bitset using integer number?(a) bitset b;(b) bitset b(12);(c) bitset b(string(“1100”));(d) bitset b(float(12));I had been asked this question in semester exam.Asked question is from Bitset in division Class Hierarchies, Library & Containers of C++

Answer»

The correct choice is (b) bitset b(12);

BEST explanation: The correct way of constructing bitset using integer NUMBER is as FOLLOWS:

bitset b(integer_number);

114.

Which function is used to calculate the conjugate of a complex number?(a) conj()(b) reverse()(c) opp()(d) find_conj()The question was posed to me in unit test.My query is from Complex Library in division Class Hierarchies, Library & Containers of C++

Answer»

Correct choice is (a) conj()

Easiest explanation - <COMPLEX> header provides conj() FUNCTION to calculate the CONJUGATE of a complex NUMBER.

115.

Which of the header file is used for array type manipulation?(a) (b) (c) (d) std namespaceI had been asked this question in final exam.This intriguing question originated from Array Type Manipulation topic in division Class Hierarchies, Library & Containers of C++

Answer»

Right answer is (d) STD namespace

Best explanation: Array TYPE manipulation functions are declared incside the namespace std so you can use namespace std to use these functions.

116.

How many Pseudo-random number engines are there?(a) 1(b) 2(c) 3(d) 4The question was posed to me during an interview for a job.My question comes from Generators topic in portion Class Hierarchies, Library & Containers of C++

Answer»

Right answer is (c) 3

To explain: There are THREE TYPES of Pseudo-random number engines BASED on the algorithm they use. They are linear_congruential_engine, mersenne_twister_engine and subtract_with_carry_engine.

117.

Which of the following is the correct syntax of using pair p?(a) pair p;(b) pair p ;(c) pair [type,type] p;(d) pair p [type,type];The question was asked in an online interview.I would like to ask this question from STL topic in chapter Class Hierarchies, Library & Containers of C++

Answer» CORRECT option is (a) pair p;

Best EXPLANATION: A pair is declared using the this SYNTAX pair IDENTIFIER.
118.

What does the sequence adaptor provide?(a) Insertion(b) Deletion(c) Interface to sequence container(d) Insertion & DeletionThe question was posed to me during an interview for a job.Query is from Sequence Adapters topic in portion Class Hierarchies, Library & Containers of C++

Answer»

Correct ANSWER is (c) Interface to sequence CONTAINER

To EXPLAIN: Sequence ADAPTOR provides interface to sequence container.

119.

What is meant by standard c++ library?(a) It is the collection of class definitions for standard data structures and a collection of algorithms(b) It is a header file(c) Collection of algorithms(d) Step by step processThe question was posed to me in an interview.My doubt is from Standard Library Design in division Class Hierarchies, Library & Containers of C++

Answer» CORRECT option is (a) It is the collection of CLASS definitions for standard data structures and a collection of algorithms

Explanation: It is the collection of class definitions for standard data structures. This part of the LIBRARY was DERIVED from the Standard Template Library.
120.

Pick out the wrong header file about strings.(a) (b) (c) (d) I had been asked this question in an interview for internship.Query is from Standard Library Design topic in portion Class Hierarchies, Library & Containers of C++

Answer»

Right option is (c) <IOS>

For explanation: The STANDARD header files for string is string and regex. So the WRONG ONE presented here is ios.

121.

To which of the following access specifiers are applicable?(a) Member data(b) Functions(c) Both Member data & Functions(d) Protected membersThis question was posed to me in quiz.My question is from Access Control topic in section Class Hierarchies, Library & Containers of C++

Answer»

Right answer is (c) Both Member DATA & Functions

To EXPLAIN I WOULD SAY: The access specifiers can be applicable to the member data and functions because they need to be accessed outside the block.

122.

Which design patterns benefit from the multiple inheritances?(a) Adapter and observer pattern(b) Code pattern(c) Glue pattern(d) Star patternThis question was addressed to me by my college director while I was bunking the class.Asked question is from Multiple Inheritance topic in portion Class Hierarchies, Library & Containers of C++

Answer»

Correct OPTION is (a) ADAPTER and OBSERVER pattern

Easiest explanation - Adapter and observer patterns benefit from the MULTIPLE INHERITANCES.

123.

Which of the following queue container can expand or shrink from both directions?(a) deque(b) queue(c) priority queue(d) stackI had been asked this question during a job interview.I'd like to ask this question from More Containers topic in chapter Class Hierarchies, Library & Containers of C++

Answer» CORRECT choice is (a) deque

Explanation: Deque is a short form for a DOUBLY ENDED queue which can be expanded and shrinked from any SIDE of the queue either from the FRONT or from the back.
124.

What happens when no argument is supplied to reset() function?(a) All bits are set to 1 in a bitset(b) All bits are set to 0 in a bitset(c) All alternate bits are set to 0 in a bitset(d) First bit is set to 0I have been asked this question in my homework.I want to ask this question from Bitset in section Class Hierarchies, Library & Containers of C++

Answer» RIGHT option is (b) All bits are SET to 0 in a BITSET

For explanation: When no argument is SUPPLIED to reset() FUNCTION i.e. function is called with empty parameters then all the bits of the bitset is set to 0.
125.

What are different operations are used in Pseudo-random number engines?(a) operator()(b) min()(c) max()(d) all of the mentionedI had been asked this question at a job interview.The doubt is from Generators in chapter Class Hierarchies, Library & Containers of C++

Answer»

Correct choice is (d) all of the mentioned

Easy EXPLANATION - Pseudo-random NUMBER engines use three operations operator() that generates a random number, MIN() that returns minimum VALUE returned by MEMBER operator() and max() returns the maximum value.

126.

What is sequence container arrays?(a) C-like arrays(b) Template class sequence container, alternative for C-like arrays(c) Collection of data of the same type(d) Collection of objectsI have been asked this question by my college director while I was bunking the class.The query is from seq_con Array Class in portion Class Hierarchies, Library & Containers of C++

Answer»

Correct option is (b) TEMPLATE class sequence container, alternative for C-like ARRAYS

Explanation: Sequence Containers arrays are an alternative for C-like arrays. It is a static continuous ARRAY that USES template CLASSES with extended features for array implementation.

127.

What are the design requirements for building a container from the sratch?(a) Container interface requirements(b) Allocator interface requirements(c) Iterator requirements(d) All of the mentionedI had been asked this question at a job interview.My question is from Defining a New Container in section Class Hierarchies, Library & Containers of C++

Answer»

The CORRECT choice is (d) All of the mentioned

To EXPLAIN I would say: These are the DESIGN SPECIFIC requirements for building a container from the SCRATCH.

128.

What do all STL containers define?(a) Iterator types(b) Begin methods(c) End methods(d) All of the mentionedI have been asked this question in final exam.My question is based upon Defining a New Container in portion Class Hierarchies, Library & Containers of C++

Answer» CORRECT answer is (d) All of the mentioned

Easy explanation - All the STL CONTAINERS define the iterator types for that container, e.g., iterator and const_iterator, e.g., vector::iterator and the BEGIN/end METHODS for that container, e.g., begin() and end().
129.

Which are presented in the container adaptors?(a) stack(b) queue(c) priority_queue(d) all of the mentionedThe question was posed to me in class test.This intriguing question comes from Sequence Adapters in division Class Hierarchies, Library & Containers of C++

Answer»

The CORRECT option is (d) all of the MENTIONED

The explanation: These mentioned things are presented in CONTAINER ADAPTERS.

130.

What is the default value of a bitset?(a) All bits are 0(b) All bits are 1(c) Leftmost bit is 0(d) Rightmost bit is 0This question was addressed to me in an interview.My doubt is from Bitset topic in division Class Hierarchies, Library & Containers of C++

Answer»

Correct CHOICE is (a) All BITS are 0

Explanation: By default, all the bits of a BITSET variable is set to 0 i.e. the VALUE of bitset variable is 0.

131.

Which operator is used to access the nth bit in a bitset?(a) ->(b) [](c) .(d) *This question was addressed to me in quiz.The origin of the question is Bitset in portion Class Hierarchies, Library & Containers of C++

Answer»

The correct answer is (b) []

The best I can explain: [] operator is used to access the NTH bit of a bitset from the right SIDE. For EXAMPLE, if my bitset b is 1010 then b[0] represents 0 and b[1] represents 1.

132.

Which of the following syntax is used to convert any variable to its original type?(a) any_cast();(b) any_cast(variable_name);(c) (variable_name);(d) any_cast(variable_name);This question was addressed to me during an interview for a job.My question is based upon STL Container Any topic in chapter Class Hierarchies, Library & Containers of C++

Answer» RIGHT option is (d) any_cast(variable_name);

Easiest explanation - The syntax USED to convert the any variable to its ORIGINAL TYPE is as follows:
133.

What do we return if we use simple array on a internal container?(a) Methods(b) Pointers(c) Objects(d) ValuesThis question was addressed to me in exam.This interesting question is from Defining a New Container topic in division Class Hierarchies, Library & Containers of C++

Answer» CORRECT option is (b) Pointers

Best explanation: Pointers are legal ITERATORS, so if your internal CONTAINER is a simple C ARRAY, then all you need to do is RETURN the pointers.
134.

To what type of object does the container can be instantiated?(a) int(b) float(c) double(d) any type of objectI got this question by my school principal while I was bunking the class.The question is from Almost Containers topic in section Class Hierarchies, Library & Containers of C++

Answer» CORRECT OPTION is (d) any type of object

Explanation: All type of object does the CONTAINER can be INSTANTIATED.
135.

To which type of class, We can apply RTTI?(a) Encapsulation(b) Polymorphic(c) Derived(d) StaticI got this question in a job interview.Asked question is from Run Time Type Information in section Class Hierarchies, Library & Containers of C++

Answer»

The CORRECT choice is (b) POLYMORPHIC

The explanation: RTTI is AVAILABLE only for CLASSES which are polymorphic, which means they have at least one virtual method.

136.

Why do we need relationships between classes?(a) To use the functionality of one class into other(b) To enhance the communication between classes(c) To increase code re-usability(d) All of the mentionedThe question was posed to me by my college professor while I was bunking the class.Question is from Class Relationships topic in division Class Hierarchies, Library & Containers of C++

Answer»

The correct OPTION is (d) All of the mentioned

The explanation: Relationships are needed to increase the use of features of one class into the other classes i.e. INCREASING the re-usability of CODES and increasing COMMUNICATION between classes.

137.

What happens when no argument is supplied to set() function?(a) All alternate bits are set to 1 in a bitset(b) All bits are set to 0 in a bitset(c) All bits are set to 1 in a bitset(d) First bit is set to 1The question was posed to me in an online quiz.The question is from Bitset in chapter Class Hierarchies, Library & Containers of C++

Answer»

The CORRECT OPTION is (c) All bits are set to 1 in a bitset

The EXPLANATION: When no argument is SUPPLIED to set() function i.e. function is CALLED with empty parameters then all the bits of the bitset is set to 1.

138.

Which header file is required for using bitset in your program?(a) (b) (c) (d) The question was asked in an interview for job.This question is from Bitset topic in division Class Hierarchies, Library & Containers of C++

Answer» CORRECT choice is (b)

BEST explanation: header FILE is required to USE the functionality of bitsets in your program i.e. use of binary string in your program.
139.

Which header file is required to use heap in your program?(a) (b) (c) (d) The question was asked in a job interview.Question is from STL in chapter Class Hierarchies, Library & Containers of C++

Answer»

The correct option is (b)

The best explanation: header file is required to use the FUNCTIONALITY of the HEAP container PROVIDED by C++.

140.

Which is the following is syntactically correct for vector v?(a) vector :: const_iterator itr = v.rbegin();(b) vector :: reverse_iterator itr = v.begin();(c) vector :: iterator itr = v.begin();(d) vector :: iterator itr = v.cbegin();I have been asked this question in class test.This interesting question is from seq_con Vector Class in chapter Class Hierarchies, Library & Containers of C++

Answer» CORRECT option is (c) vector :: ITERATOR itr = v.begin();

To explain I would say: v.rbegin() returns itertor of reverse iterator therefore cannot be stored in const_iterator(TYPE MISMATCH). Similarly v.begin() returns normal iterator therefore cannot be stored in reverse_iterator and v.cbegin() returns the const_iterator therefore cannot be stored in normal iterator.
141.

How many types of container classes are there in c++?(a) 1(b) 2(c) 3(d) As many as possibleI have been asked this question during an interview for a job.My doubt is from Defining a New Container in chapter Class Hierarchies, Library & Containers of C++

Answer» CORRECT OPTION is (B) 2

To explain: There are two type of CONTAINER classes in c++. They are VALUE containers and reference containers.
142.

Which of the following will return the new element at the end of container?(a) front(b) back(c) push_back(d) pop_backThe question was asked in an international level competition.My question is based upon Sequences topic in chapter Class Hierarchies, Library & Containers of C++

Answer»

The CORRECT option is (b) BACK

The best EXPLANATION: Q3: back() in containers are used to access the last ELEMENT of the SEQUENCE.

143.

Which statement is incorrect about virtual function.(a) They are used to achieve runtime polymorphism(b) They are used to hide objects(c) Each virtual function declaration starts with the virtual keyword(d) All of the mentionedThis question was posed to me by my college director while I was bunking the class.My query is from Inheritance in portion Class Hierarchies, Library & Containers of C++

Answer» RIGHT CHOICE is (b) They are used to hide objects

Best explanation: VIRTUAL function are used to achieve runtime polymorphism by CALLING the right function during runtime. Their declaration STARTS with a virtual keyword.
144.

What is meant by multiple inheritance?(a) Deriving a base classfrom derived class(b) Deriving a derived class from base class(c) Deriving a derived class from more than one base class(d) Deriving a derived base classI had been asked this question in a national level competition.Origin of the question is Multiple Inheritance in section Class Hierarchies, Library & Containers of C++

Answer»

Right choice is (c) DERIVING a DERIVED class from more than one base class

To explain I WOULD say: MULTIPLE INHERITANCE enables a derived class to inherit members from more than one parent.

145.

Which function is used to get the absolute of a complex number?(a) ret()(b) norm()(c) mod()(d) abs()I had been asked this question in an interview.My question is based upon Complex Library topic in portion Class Hierarchies, Library & Containers of C++

Answer»

Correct OPTION is (d) ABS()

Explanation: abs() FUNCTION is provided by theheader to calculate the absolute value of a complex number.

146.

Which function is used to get the imaginary part of the complex number?(a) real()(b) imag()(c) imag_p()(d) real_p()This question was addressed to me by my college director while I was bunking the class.My query is from Complex Library topic in section Class Hierarchies, Library & Containers of C++

Answer» CORRECT choice is (B) imag()

To explain: The imag() FUNCTION is provided by the complex
to access the imaginary PART of a complex number object.
147.

Which of the following is correct about remove_extent() function?(a) Removes the given dimension from an array(b) Removes the first dimension from the right of the array(c) Removes the first dimension from the left of the array(d) Removes the last dimension from the left of the arrayI had been asked this question in an online interview.This is a very interesting question from Array Type Manipulation topic in division Class Hierarchies, Library & Containers of C++

Answer» RIGHT answer is (C) Removes the FIRST dimension from the left of the ARRAY

For explanation: remove_extent() function removes the first dimension i.e. the first dimension from the GIVEN array.
148.

Which algorithm is used in subtract_with_carry_engine?(a) Mersenne Twister algorithm(b) Lagged fibonacci generator algorithm(c) Either the Mersenne Twister algorithm or Lagged fibonacci generator algorithm(d) Fibonacci generatorThe question was posed to me in final exam.I would like to ask this question from Generators in division Class Hierarchies, Library & Containers of C++

Answer»

The CORRECT answer is (b) Lagged fibonacci generator algorithm

Best EXPLANATION: The algorithm USED in subtract_with_carry_engine is lagged fibonacci generator, with STATE sequences.

149.

Aggregation is a __________ type of Association relationship.(a) strong(b) weak(c) unnecessary(d) necessaryI got this question by my school principal while I was bunking the class.This interesting question is from Class Relationships in division Class Hierarchies, Library & Containers of C++

Answer»

Right OPTION is (b) weak

To EXPLAIN I would say: Aggregation is a weak type of Association relationship because in this case objects of related CLASSES can OCCUR independently. For example, bank and employee can occur independently.

150.

What is subtract_with_carry_engine?(a) Pseudo-random number engine that generates random unsigned integers(b) Pseudo-random number engine that generates random unsigned integers in the range [0, 2^w-1] for some w using Mersenne Twister algorithm(c) Pseudo-random number engine that generates random unsigned integers in the range [0, 2^w-1] for some w using lagged Fibonacci generator(d) Pseudo-random number engine that generates random signed integers in the range [0, 2^w-1] for some w using Mersenne Twister algorithmThe question was posed to me in an internship interview.This intriguing question comes from Generators topic in portion Class Hierarchies, Library & Containers of C++

Answer»

Correct choice is (C) Pseudo-random NUMBER engine that GENERATES random unsigned integers in the range [0, 2^W-1] for some w using lagged Fibonacci generator

For EXPLANATION: subtract_with_carry_engine is a Pseudo-random number engine that generates random unsigned integers in the range [0, 2^w-1] for some w using lagged Fibonacci generator.