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.

51.

How can the member functions in the container be accessed?(a) Iterator(b) Indirect(c) Both Iterator & Indirect(d) VectorThe question was posed to me during an internship interview.This interesting question is from Container Design in division Class Hierarchies, Library & Containers of C++

Answer»

The correct OPTION is (a) Iterator

The BEST explanation: The CONTAINER manages the STORAGE SPACE for its elements and provides member functions to access them, either directly or through iterators which reference objects with similar properties to pointers.

52.

Which operators are used in the free store?(a) new(b) delete(c) both new & delete(d) terminateThis question was addressed to me at a job interview.Asked question is from Free Store topic in section Class Hierarchies, Library & Containers of C++

Answer»

Correct answer is (C) both new & delete

The best I can EXPLAIN: new and delete operators are USED to allocate and deallocate the MEMORY for the program.

53.

What is the Run-Time Type Information?(a) Information about an object’s data type at runtime(b) Information about the variables(c) Information about the given block(d) Information about the functionsThe question was asked in quiz.The doubt is from Run Time Type Information in chapter Class Hierarchies, Library & Containers of C++

Answer»

The correct option is (a) Information about an object’s DATA type at RUNTIME

Easiest explanation - With the help of RTTI, We can GET the information about the data type at the runtime.

54.

What is Inheritance in C++?(a) Wrapping of data into a single class(b) Deriving new classes from existing classes(c) Overloading of classes(d) Classes with same namesThe question was asked in class test.This interesting question is from Inheritance topic in division Class Hierarchies, Library & Containers of C++

Answer»

Correct ANSWER is (B) Deriving NEW classes from EXISTING classes

The best explanation: INHERITANCE is the concept of OOPs in which new classes are derived from existing classes in order to reuse the properties of classes defined earlier.

55.

What is the use of clog?(a) Standard logging stream(b) Error stream(c) Input stream(d) output streamThe question was posed to me during an interview for a job.I want to ask this question from Class Hierarchies Introduction in section Class Hierarchies, Library & Containers of C++

Answer»

Correct option is (a) Standard LOGGING stream

Easy explanation - clog is an object of class ostream that REPRESENTS the standard logging stream. It is ASSOCIATED with the cstdio stream stderr, like CERR.

56.

Which container is used to keep priority based elements?(a) queue(b) stack(c) set(d) priority queueI got this question by my school teacher while I was bunking the class.Query is from More Containers in portion Class Hierarchies, Library & Containers of C++

Answer»

Right option is (d) priority queue

For explanation: C++ provides priority queue container that stores elements BASED on their priority. For EXAMPLE, if the ABSOLUTE value is the priority then -6 will be kept before 4 in the priority queue.

57.

Which container is best to keep the collection of distinct elements?(a) multimap(b) heap(c) set(d) queueThe question was asked during an interview.This question is from More Containers topic in section Class Hierarchies, Library & Containers of C++

Answer» CORRECT choice is (c) SET

Best explanation: C++ PROVIDES a set container to store a collection of DISTINCT ELEMENTS. This container behaves similar to mathematical sets.
58.

How many types of Association can be there between classes?(a) 1(b) 2(c) 3(d) 4I have been asked this question in unit test.The origin of the question is Class Relationships in chapter Class Hierarchies, Library & Containers of C++

Answer»

Right ANSWER is (d) 4

The EXPLANATION is: There can be FOUR TYPES of an ASSOCIATION relationship between classes namely one-to-one, one-to-many, many-to-one and many-to-many.

59.

What is any in C++?(a) STL container used to store a single value of any type(b) Exception class in C++(c) Fundamental type provided by C++(d) Template data typeThis question was posed to me in my homework.I want to ask this question from STL Container Any in section Class Hierarchies, Library & Containers of C++

Answer» RIGHT CHOICE is (a) STL CONTAINER used to STORE a single value of any type

The explanation: Any is an STL container provided by C++ to store value or objects of any type.
60.

Which of the following operations can be performed on a pair?(a) Assignment of pairs(b) Copying of one pair to another(c) Comparison of two pairs(d) All of the mentionedThe question was asked at a job interview.This is a very interesting question from STL topic in portion Class Hierarchies, Library & Containers of C++

Answer»

Correct CHOICE is (d) All of the mentioned

Best EXPLANATION: A pair can be assigned, copied or can be COMPARED. Hence all the above operations can e performed on PAIRS.

61.

Which header file is required to use pair container in your program?(a) (b) (c) (d) I had been asked this question in semester exam.The above asked question is from STL in chapter Class Hierarchies, Library & Containers of C++

Answer»

The correct OPTION is (b)

Easy explanation - PAIR CONTAINER is DEFINED under the header file THEREFORE one should includeheader before using pair container.

62.

Which function is used to get the total capacity of a vector?(a) v.size()(b) v.capacity()(c) v.max_size()(d) v.no_of_elements()This question was addressed to me during a job interview.This intriguing question comes from seq_con Vector Class in section Class Hierarchies, Library & Containers of C++

Answer»

Correct CHOICE is (b) v.capacity()

The best explanation: capacity() FUNCTION is used to get the total number of elements that can be stored at PRESENT in the vector.

63.

Pick the incorrect statement.(a) Vectors have a dynamic size(b) Vectors are placed in contiguous storage(c) Insertion in vectors always takes constant time(d) Vectors insert the element at the endThe question was asked during an interview for a job.My enquiry is from seq_con Vector Class in chapter Class Hierarchies, Library & Containers of C++

Answer»

The correct option is (c) INSERTION in vectors always takes CONSTANT time

Explanation: Insertion in vectors are not always constant. When we are inserting an element at the end of the vector then if a vector is FULL then it needs to size itself which takes time to resize and time to insert element else just time for inserting that element at the end. Hence the insertion time is not constant always. Vectors have a dynamic size. They are placed in contiguous MEMORY for easy access.

64.

Which of the follwoing function(s) of Array classes are similar to [] operator?(a) at()(b) get()(c) both at() and get()(d) front()I had been asked this question in exam.I'd like to ask this question from seq_con Array Class topic in division Class Hierarchies, Library & Containers of C++

Answer»

The correct CHOICE is (c) both at() and GET()

Explanation: Both at() and get() function are used to ACCESS the elements stored at i’TH position of the array.

65.

What do container adapter provide to interface?(a) Restricted interface(b) More interface(c) No interface(d) Memory interfaceThe question was asked during a job interview.This is a very interesting question from Sequence Adapters in section Class Hierarchies, Library & Containers of C++

Answer» RIGHT option is (a) Restricted interface

To EXPLAIN: A container adapter PROVIDES a restricted interface to a container.In PARTICULAR, adapters do not provide iterators; they are intended to be used only through their SPECIALIZED interfaces.
66.

Which of the following type does the container should define?(a) Iterator type(b) Vector type(c) Storage type(d) Memory typeThe question was posed to me in an interview for internship.Query is from Container Design topic in chapter Class Hierarchies, Library & Containers of C++

Answer»

The correct option is (a) ITERATOR type

Explanation: Every container MUST define an iterator type. ITERATORS allow algorithms to iterate over the container’s CONTENTS.

67.

Which is used for manually writing lookup table?(a) std:map(b) std:lookup(c) std:find(d) std:lockThis question was posed to me during an interview.I need to ask this question from Container Design in chapter Class Hierarchies, Library & Containers of C++

Answer»

Correct answer is (a) STD:map

Explanation: LOOKUP table means storing values in a table with unique keys for each value so that can be CHECKED in future easily. So for such lookup tables maps are USED in C++.

68.

Which is used to allocate and deallocate storage for objects during the execution?(a) Stack(b) Heap(c) Freestore(d) QueueThe question was posed to me during an interview.The above asked question is from Free Store topic in section Class Hierarchies, Library & Containers of C++

Answer»

The correct option is (C) Freestore

Easy EXPLANATION - Free STORE is a pool of memory available for you to allocate and deallocate STORAGE for objects during the execution of your PROGRAM.

69.

Which operators are part of RTTI?(a) dynamic_cast()(b) typeid(c) both dynamic_cast & typeid(d) dynamic_cast[]The question was asked during an internship interview.My question comes from Run Time Type Information in portion Class Hierarchies, Library & Containers of C++

Answer»

Correct ANSWER is (C) both dynamic_cast<> & typeid

Explanation: The dynamic_cast<> operation and typeid operator in C++ are part of RTTI.

70.

How many specifiers are used to derive a class?(a) 1(b) 2(c) 3(d) 4The question was asked during an interview.My question is based upon Inheritance in section Class Hierarchies, Library & Containers of C++

Answer»

Right CHOICE is (C) 3

To EXPLAIN: There are 3 specifiers USED to DERIVE a class. They are private, protected and public.

71.

Which classes are called as mixin?(a) Represent a secondary design(b) Classes express functionality which represents responsibilities(c) Standard logging stream(d) Represent a priary designThis question was posed to me in a national level competition.My question is from Class Hierarchies Introduction in section Class Hierarchies, Library & Containers of C++

Answer»

The correct option is (b) Classes express FUNCTIONALITY which represents responsibilities

The best I can explain: A class that EXPRESSES functionality rather than its PRIMARY design role is CALLED a MIXIN.

72.

Which type of relationship is modelled by Inheritance?(a) Is-A relationship(b) Has-A relationship(c) Part-Of relationship(d) Belongs-to relationshipThis question was addressed to me in an international level competition.I would like to ask this question from Class Relationships in division Class Hierarchies, Library & Containers of C++

Answer»

The correct OPTION is (a) Is-A relationship

Best explanation: Inheritance models Is-A TYPE of relationship between classes. This is because in this case DERIVED class inherits all property of the BASE class and Is-A type of B class.

73.

What is the use of the set() function in bitset?(a) Used to make alternate bits zero(b) Used to make a bit 0 in a bitset(c) Used to make all bits zero(d) Used to set bit(s) in a bitsetI had been asked this question by my school principal while I was bunking the class.This intriguing question comes from Bitset in section Class Hierarchies, Library & Containers of C++

Answer» CORRECT choice is (d) Used to set bit(s) in a bitset

The EXPLANATION: header PROVIDES the set() FUNCTION to set bit(s) to 1 in a bitset variable.
74.

Which of the following is correct about any() function in bitset?(a) Returns true if the number of 1’s equal to the number of 0’s(b) Returns true if any bit is set 0(c) Returns true if any bit is set 1(d) Returns true only if all bits are 1The question was posed to me in an internship interview.Question is from Bitset in chapter Class Hierarchies, Library & Containers of C++

Answer»

The correct choice is (c) Returns TRUE if any bit is SET 1

The best explanation: header PROVIDES the any() FUNCTION which returns true if any of the bit is set to 1 in the bitset variable.

75.

Which of the following is correct about extent() function?(a) Returns how many elements are in array currently(b) Returns the size of the 1st dimension(c) Returns how many total elements can be stored in an array(d) Returns the size of a given dimensionThe question was posed to me in an interview for internship.The question is from Array Type Manipulation in portion Class Hierarchies, Library & Containers of C++

Answer»

The CORRECT choice is (d) RETURNS the size of a GIVEN dimension

Best explanation: The EXTENT() function takes two parameters one DENOTING the array other showing the dimension for which the size we want to know.

76.

Which header file is used for generating random numbers?(a) (b) (c) (d) I got this question during an interview for a job.My query is from Generators topic in chapter Class Hierarchies, Library & Containers of C++

Answer»

The CORRECT answer is (d) <RANDOM>

Easiest explanation - header FILE is REQUIRED for using GENERATORS and distributions which helps in generating random numbers in a program.

77.

What is the full form of vptr?(a) Vector Pointer(b) Virtual Pointer(c) V type Pointer(d) Virtual-vector PointerThis question was addressed to me at a job interview.The origin of the question is vtable and vptr in division Class Hierarchies, Library & Containers of C++

Answer»

Correct answer is (a) VECTOR POINTER

To explain: VPTR is abbreviated for a virtual pointer which is USED to POINT virtual tables of a class.

78.

Which exception is thrown if the typecasting is not done properly?(a) bad_type_cast(b) bad_any_cast(c) type_mismatched(d) bad_cast_mismatchedThis question was posed to me in unit test.My enquiry is from STL Container Any topic in section Class Hierarchies, Library & Containers of C++

Answer»

Correct choice is (b) bad_any_cast

Best explanation: bad_any_cast exception is thrown when TYPECASTING is not done properly by the USER i.e. if any is storing INT value and we are TRYING to cast it into a string then the program will throw bad_any_cast exception.

79.

What is the difference between begin() and cbegin() in vectors?(a) both are same(b) begin() returns iterator to first element and cbegin() returns iterator to last element(c) begin() returns an iterator to first element whereas cbegin() returns constant iterator to first element(d) begin() returns returns first element cbegin() returns voidI have been asked this question by my college professor while I was bunking the class.My query is from seq_con Vector Class in division Class Hierarchies, Library & Containers of C++

Answer»

Correct choice is (c) begin() returns an ITERATOR to first element whereas cbegin() returns constant iterator to first element

The best I can explain: Both begin() and cbegin() are used to ACCESS the first element of the VECTOR. The function begin() returns an iterator to first element whereas cbegin() returns a constant iterator to first element.

80.

Pick the correct statement.(a) Sequence Container arrays know (somehow stores within) its size whereas C-like arrays do not(b) Sequence Container arrays have no advantage over C-like arrays(c) Sequence Container arrays are same as C-like arrays(d) Sequence Container arrays are also present in CI have been asked this question during an online interview.Enquiry is from seq_con Array Class topic in division Class Hierarchies, Library & Containers of C++

Answer»

The CORRECT ANSWER is (a) Sequence Container ARRAYS know (somehow stores within) its size whereas C-like arrays do not

To explain: Sequence CONTAINERS Arrays stores its size within itself so need to pass extra size parameter when passing this ARRAY as an argument.

81.

How many iterators are needed for the defining a new container?(a) 1(b) 2(c) 3(d) 4This question was posed to me in an online quiz.My query is from Defining a New Container topic in portion Class Hierarchies, Library & Containers of C++

Answer»

The correct choice is (c) 3

Best explanation: There are three main ITERATORS needed for designing a container. They are CONST iterator, REVERSE iterator and Iterator traits.

82.

What kind of library is Standard Template Library?(a) Polymorphic(b) Generic(c) Both Polymorphic & Generic(d) VirtualThe question was asked during an online exam.This interesting question is from Almost Containers in portion Class Hierarchies, Library & Containers of C++

Answer»

Right CHOICE is (b) Generic

The explanation is: The STL is a generic LIBRARY, MEANING that its COMPONENTS are heavily parameterized.

83.

What will happen when introduce the interface of classes in a run-time polymorphic hierarchy?(a) Separation of interface from implementation(b) Merging of interface from implementation(c) Separation of interface from debugging(d) Merging of interface from debuggingThe question was posed to me by my school principal while I was bunking the class.My question is taken from Class Hierarchies Introduction topic in division Class Hierarchies, Library & Containers of C++

Answer»

Right option is (a) SEPARATION of interface from implementation

The BEST I can EXPLAIN: Separation of interface from implementation INTRODUCE the interface of classes in a run-time POLYMORPHIC hierarchy.

84.

Sets are implemented using _______________________(a) binary search tree(b) red black tree(c) avl tree(d) heapThis question was addressed to me during an interview for a job.My enquiry is from More Containers in section Class Hierarchies, Library & Containers of C++

Answer»

The correct answer is (a) binary search tree

Explanation: Sets are implemented USING the search tree so that we can CHECK the presence of any element to be INSERTED in O(logn) time in order to REMOVE conflicts between elements.

85.

Which type of relationship is modelled by Composition?(a) Is-A relationship(b) Has-A relationship(c) Part-Of relationship(d) Have-A relationshipThis question was addressed to me in my homework.My question is taken from Class Relationships topic in division Class Hierarchies, Library & Containers of C++

Answer» RIGHT option is (c) PART-Of relationship

The explanation: Composition models the part-of relationship between CLASSES. In this CHILDREN cannot exits without a parent, therefore, they are part of each other.
86.

What is the class relationship?(a) A relationship between classes that tells how they are related(b) A relationship between classes that tells how much power one class has over other class(c) A relationship between classes that tells which parts of a class is visible to other classes(d) All of the mentionedThis question was addressed to me in an internship interview.My question is taken from Class Relationships topic in division Class Hierarchies, Library & Containers of C++

Answer»

Correct option is (d) All of the mentioned

Explanation: The Class relationship is a CONCEPT that helps us in DIFFERENTIATING how ONE class is RELATED to other classes, the power of one over other and which part one class can be accessed by other class.

87.

Which of the following is correct about none() function in bitset?(a) Returns true if any bits is set 1(b) Returns true if all bits is set 0(c) Returns true if the number of 1’s equal to the number of 0’s(d) Returns true only if all bits are 1I got this question during an interview.This interesting question is from Bitset topic in division Class Hierarchies, Library & Containers of C++

Answer»

Correct choice is (b) Returns true if all bits is set 0

Easiest EXPLANATION - HEADER PROVIDES the any() FUNCTION which returns true if none of the bit is set to 1 in the bitset variable.

88.

Which header file is required to use complex class in your program?(a) (b) (c) (d) The question was posed to me in an online interview.I want to ask this question from Complex Library topic in division Class Hierarchies, Library & Containers of C++

Answer»

The CORRECT ANSWER is (a) <COMPLEX>

Easiest EXPLANATION - header file is required to use the functionalitites of complex NUMBERS.

89.

What is vtable in C++?(a) Lookup table to resolve function calls in dynamic manners(b) Lookup table to resolve function calls in static manners(c) Lookup table to see which are the functions available for calls throughout the program(d) Lookup table to check how many functions are there int he programThe question was posed to me in final exam.My question comes from vtable and vptr in division Class Hierarchies, Library & Containers of C++

Answer» CORRECT option is (a) Lookup table to RESOLVE function calls in dynamic MANNERS

The explanation: VTABLE is a lookup table that is used to resolve the function calls in dynamic/late binding manners.
90.

Which function is used to construct heap from given sequence of numbers?(a) create_heap()(b) make_heap()(c) construct_heap()(d) start_heap()I have been asked this question in an internship interview.This question is from STL topic in chapter Class Hierarchies, Library & Containers of C++

Answer»

Right answer is (b) make_heap()

The EXPLANATION: C++ STL-heap CONTAINER provides make_heap() FUNCTION to convert a GIVEN range of number into heap.

91.

In which context does the stack operates?(a) FIFO(b) LIFO(c) Both FIFO & LIFO(d) LIFIThe question was posed to me in quiz.My question is taken from Sequence Adapters topic in portion Class Hierarchies, Library & Containers of C++

Answer»

Right choice is (b) LIFO

Easiest EXPLANATION - A stack is a container where elements OPERATE in a LIFO CONTEXT, where elements are inserted (PUSHED) and removed (POPPED) from the end of the container.

92.

What is meant by type_info?(a) Used to hold the type information returned by the typeid operator(b) Used to hold the type information returned by the dynamic_cast(c) Used to hold the type information returned by the static_cast(d) Used to hold the type information returned by the static_idThe question was posed to me in examination.I'd like to ask this question from Run Time Type Information topic in chapter Class Hierarchies, Library & Containers of C++

Answer»

Right choice is (a) Used to HOLD the type INFORMATION RETURNED by the typeid operator

The BEST I can explain: type_info is used to hold the type information returned by the typeid operator.

93.

Unordered map is implemented using _________________(a) binary search tree(b) red black tree(c) heap(d) hash tableI got this question at a job interview.My doubt is from More Containers in division Class Hierarchies, Library & Containers of C++

Answer»

Correct option is (d) hash table

Easiest explanation - As unordered MAP has no order of KEYS therefore hash table is USED to store key-value PAIRS in a hash table.

94.

Which container can have the same keys?(a) map(b) multimap(c) unordered map(d) setI got this question in an international level competition.The above asked question is from More Containers topic in section Class Hierarchies, Library & Containers of C++

Answer»

The correct OPTION is (b) multimap

To explain I would SAY: C++ provide multimap CONTAINER that is USED to MAKE map that can contain same keys i.e. {a: 5} and {a:10} both can exist.

95.

Which of the following is the correct syntax of declaring a complex number?(a) complex variable_name;(b) complex variable_name;(c) Complex variable_name;(d) Complex variable_name;The question was asked in an interview.My question is from Complex Library topic in section Class Hierarchies, Library & Containers of C++

Answer»

Correct answer is (B) complex variable_name;

Best explanation: The correct SYNTAX of DECLARING a complex number OBJECT is complex variable_name.

96.

What is the use of is_same() function in C++?(a) To check if a variable is array type or not(b) To check whether two variables have the same characteristics(c) To check if two variable is of array type or not(d) To check whether two variables are different or notThis question was posed to me by my school principal while I was bunking the class.This question is from Array Type Manipulation topic in division Class Hierarchies, Library & Containers of C++

Answer» RIGHT CHOICE is (b) To CHECK whether two variables have the same characteristics

Explanation: is_same() function is USED to check whether two variables have the same characteristics or not.
97.

Which of the following is correct syntax of making heap from a vector v?(a) make_heap(v.elements);(b) make_heap(v);(c) make_heap(v.end(), v.begin());(d) make_heap(v.begin(), v.end());This question was posed to me during an interview.My question is from STL in portion Class Hierarchies, Library & Containers of C++

Answer»

Correct ANSWER is (d) make_heap(v.begin(), v.end());

The explanation: To construct HEAP USNG the vector elements one need to use the FOLLOWING syntax make_heap(v.begin(), v.end()); which is taking the ITERATOR to first and last element of the vector using which elements of vector can be accessed and heap can be constructed.

98.

What is the use of front() function in heap?(a) Returns the element closest to the median of a sequence(b) Returns the last element of the heap(c) Returns the first element of the heap(d) Returns the element closest to mean of a sequenceThis question was posed to me by my college professor while I was bunking the class.My question comes from STL in division Class Hierarchies, Library & Containers of C++

Answer»

The CORRECT choice is (c) Returns the first element of the heap

Easiest EXPLANATION - C++ STL-heap CONTAINER provides the front() function that returns the first element of the heap i.e. the MAXIMUM number of the sequence.

99.

Which of the following(s) can be used to access the last element of a vector v?(a) v.end()(b) v.cend()(c) both v.end() and v.cend()(d) vectors do not have a function to access the last elementThe question was posed to me during an internship interview.I want to ask this question from seq_con Vector Class topic in portion Class Hierarchies, Library & Containers of C++

Answer»

Right answer is (d) vectors do not have a function to access the last element

The EXPLANATION: There are no function to access the last element of the VECTOR. The end() and CEND() returns the ITERATOR to an element which is kept at the last of the vector to keep the knowledge about the end of a vector. In order to access the last element, you can first find the size and then can use V[size-1] or v.at(size – 1) to access the last element.

100.

Members of which access specifiers are not inherited?(a) Public(b) Protected(c) Private(d) None of the mentionedThe question was posed to me in an interview for internship.My enquiry is from Access Control topic in portion Class Hierarchies, Library & Containers of C++

Answer»

Right choice is (d) NONE of the mentioned

Explanation: All the data members and member FUNCTIONS of a class are PRIVATE by DEFAULT.