InterviewSolution
Saved Bookmarks
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. |
What is a friend function in C++?(a) A function which can access all the private, protected and public members of a class(b) A function which is not allowed to access any member of any class(c) A function which is allowed to access public and protected members of a class(d) A function which is allowed to access only public members of a class |
|
Answer» The correct answer is (a) A function which can access all the private, protected and public members of a class To explain I would say: Friend function in C++ is a function which can access all the private, protected and public members of a class. |
|
| 102. |
To use internal linkage we have to use which keyword?(a) static(b) extern(c) static or extern(d) public |
|
Answer» The correct choice is (a) static The best I can explain: static keyword is used for internal linkage. |
|
| 103. |
Which is used to use a function from one source file to another?(a) code(b) declaration(c) prototype(d) variable |
|
Answer» Right option is (c) prototype Explanation: By defining a function’s prototype in another file means, we can inherit all the features from the source function. |
|
| 104. |
How many types of linkages are there in C++?(a) 1(b) 2(c) 3(d) 4 |
|
Answer» Correct choice is (c) 3 Easy explanation - There are three types of linkage in c++. They are an internal linkage, external linkage, and no linkage. |
|
| 105. |
Which of the following keyword is used to declare the header file?(a) include(b) exclude(c) string(d) namespace |
|
Answer» Correct choice is (a) include Explanation: The include keyword is used to include all the required things to execute the given code in the program. |
|
| 106. |
What is the user-defined header file extension in c++?(a) cpp(b) h(c) hf(d) hg |
|
Answer» Right choice is (b) h Easiest explanation - .h extensions are used for user defined header files. To include a user defined header file one should use #include”name.h” i.e. enclosed within double quotes. |
|
| 107. |
setprecision requires which of the following header file?(a) stdlib.h(b) iomanip.h(c) console.h(d) conio.h |
|
Answer» Correct answer is (b) iomanip.h Easy explanation - The iomanip header file is used to correct the precision of the values. |
|
| 108. |
Which of the following header file does not exist?(a) (b) (c) (d) |
|
Answer» The correct answer is (c) Easy explanation - There is no such header file |
|
| 109. |
To use external linkage we have to use which keyword?(a) static(b) extern(c) const(d) argc |
|
Answer» Right answer is (b) extern The best I can explain: Extern keyword is used to represent identifiers from other programs. |
|
| 110. |
Which of the header file must be included to use stringstream?(a) (b) (c) (d) |
|
Answer» Right choice is (b) Easy explanation - stringstream is available under the header file |
|
| 111. |
Why we use the “dynamic_cast” type conversion?(a) result of the type conversion is a valid(b) to be used in low memory(c) result of the type conversion is an invalid(d) it is used for storage |
|
Answer» Right answer is (a) result of the type conversion is a valid For explanation: It is used to check that operators and operands are compatible after conversion. |
|
| 112. |
What is the return type of the conversion operator?(a) void(b) int(c) float(d) no return type |
|
Answer» The correct option is (d) no return type The best explanation: Conversion operator doesn’t have any return type not even void. |
|
| 113. |
How many parameters does a conversion operator may take?(a) 0(b) 1(c) 2(d) as many as possible |
|
Answer» The correct choice is (a) 0 Explanation: 0 parameters does a conversion operator will take. |
|
| 114. |
Which container in c++ will take large objects?(a) string(b) class(c) vector(d) string & class |
|
Answer» Correct answer is (c) vector To explain I would say: Because the vector is mainly used to store large objects for the game programming and other operations etc. |
|
| 115. |
In Linux, how do the heaps and stacks are managed?(a) ram(b) secondary memory(c) virtual memory(d) static memory |
|
Answer» The correct option is (c) virtual memory Explanation: In virtual memory, We can keep track of all the objects and access them much faster than any another. |
|
| 116. |
How many constructors can present in a class?(a) 1(b) 2(c) 3(d) multiple |
|
Answer» The correct answer is (d) multiple For explanation: There can be multiple constructors of the same class, provided they have different signatures. |
|
| 117. |
What is meant by polymorphism?(a) class having many forms(b) class having only single form(c) class having two forms(d) class having four forms |
|
Answer» The correct answer is (a) class having many forms Easiest explanation - Polymorphism is literally meant class having many forms. |
|
| 118. |
How many kinds of classes are there in c++?(a) 1(b) 2(c) 3(d) 4 |
|
Answer» Correct choice is (b) 2 The best explanation: There are two kinds of classes in c++. They are absolute class and the concrete class. |
|
| 119. |
Which are done by compiler for templates?(a) type-safe(b) portability(c) code elimination(d) prototype |
|
Answer» Right answer is (a) type-safe Easiest explanation - The compiler can determine at compile time whether the type associated with a template definition can perform all of the functions required by that template definition. |
|
| 120. |
What are Container Adaptors?(a) Containers that implements data structures which can be accessed sequentially(b) Containers that implements sorted data structures for fast search in O(logn)(c) Containers that implements unsorted(hashed) data structures for quick search in O(1)(d) Containers that provide a different interface for sequential containers |
|
Answer» Right choice is (d) Containers that provide a different interface for sequential containers Easy explanation - Container Adaptors is the subset of Containers that provides a different interface for sequential containers. |
|
| 121. |
How many Container Adaptors are provided by C++?(a) 2(b) 3(c) 4(d) 5 |
|
Answer» Right option is (b) 3 For explanation: C++ provides 3 types of Container Adaptors namely Stack, Queue and Priority Queues. |
|
| 122. |
How many components STL has?(a) 1(b) 2(c) 3(d) 4 |
|
Answer» The correct choice is (d) 4 Explanation: STL has four components namely Algorithms, Containers, Functors and Iterators. |
|
| 123. |
How many types of Iterators are provided by C++?(a) 2(b) 3(c) 4(d) 5 |
|
Answer» Right option is (d) 5 Explanation: There are five types of Iterators provided by C++ namely Input Iterators, Output Iterators, Forward Iterators, Bi-directional Iterators and Random-access Iterators. |
|
| 124. |
What are the operators available in C++ for dynamic allocation and de-allocation of memories?(a) new(b) delete(c) compare(d) both new & delete |
|
Answer» Right choice is (d) both new & delete Easy explanation - new and delete operators are mainly used to allocate and deallocate during runtime. |
|
| 125. |
Which function is used to check whether a character is an alphabet or number?(a) isalpha()(b) isalnum()(c) isdigit()(d) isblank() |
|
Answer» The correct choice is (b) isalnum() The explanation is: Character classification provides isalnum() function to check whether a character in C++ is alphabet or number. |
|
| 126. |
Which function is used to check whether a character is an alphabet?(a) isalpha()(b) isalnum()(c) isdigit()(d) isblank() |
|
Answer» Correct option is (a) isalpha() The explanation: Character classification provides isalpha() function to check whether a character in C++ is an alphabet or not. |
|
| 127. |
How many types of Association can be there between classes?(a) 1(b) 2(c) 3(d) 4 |
|
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. |
|
| 128. |
How the relationship is made in Association?(a) Through the objects of classes(b) Through constructor(c) Through destructor(d) Through class Names |
|
Answer» The correct choice is (a) Through the objects of classes The best explanation: Association relationship between classes is made using the objects of classes like we have a bank object denoting ABC bank and some objects of Employee class XYZ1, XYZ2 and so on. So, in this case, XYZ1 is an employee in ABC bank so there is a relationship between these two objects. |
|
| 129. |
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 mentioned |
|
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. |
|
| 130. |
Which header file is required to use pair container in your program?(a) (b) (c) (d) |
|
Answer» The correct option is (b) Easy explanation - Pair container is defined under the header file |
|
| 131. |
In which of the following relationship objects of related classes can occur independently?(a) Aggregation(b) Association(c) Composition(d) Both Aggregation an Association |
|
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. |
|
| 132. |
What is operator overloading in C++?(a) Overriding the operator meaning by the user defined meaning for user defined data type(b) Redefining the way operator works for user defined types(c) Ability to provide the operators with some special meaning for user defined data type(d) All of the mentioned |
|
Answer» Correct answer is (d) All of the mentioned Explanation: Operator overloading helps programmer to give his/her own meaning to an operator for user defined data types(eg, classes). |
|
| 133. |
Which operator is used to declare the destructor?(a) #(b) ~(c) @(d) $ |
|
Answer» The correct option is (b) ~ The best I can explain: tilde(~) is used to declare destructor of a class. |
|
| 134. |
Which header file is required to use heap in your program?(a) (b) (c) (d) |
|
Answer» The correct option is (b) The best explanation: |
|
| 135. |
What will happen when we move to try block far away from catch block?(a) Reduces the amount of code in cache(b) Increases the amount of code in cache(c) Don’t alter anything(d) Increases the amount of code |
|
Answer» The correct answer is (a) Reduces the amount of code in cache Explanation: compilers may try to move the catch-code far away from the try-code, which reduces the amount of code to keep in cache normally, thus enhancing performance. |
|
| 136. |
What is meant by exception specification?(a) A function is limited to throwing only a specified list of exceptions(b) A catch can catch all types of exceptions(c) A function can throw any type of exceptions(d) A try can catch all types of exceptions |
|
Answer» Correct choice is (a) A function is limited to throwing only a specified list of exceptions Easiest explanation - C++ provides a mechanism to ensure that a given function is limited to throwing only a specified list of exceptions. It is called an exception specification. |
|
| 137. |
What operation can be performed by destructor?(a) Abort the program(b) Resource cleanup(c) Exit from the current block(d) Terminate the program |
|
Answer» The correct choice is (b) Resource cleanup The explanation is: It will be used to free all the resources that are used by the block of code during execution. |
|
| 138. |
What is the main purpose of the constructor?(a) Begin the execution of class(b) Include the macros for the program(c) Establish the class invariant(d) Terminate the program |
|
Answer» Right answer is (c) Establish the class invariant The best I can explain: The purpose of a constructor is to establish the class invariant. To do that, it often needs to acquire system resources or in general perform an operation that may fail. |
|
| 139. |
What will happen when a programs throws any other type of exception other than specified?(a) terminate(b) arise an error(c) run(d) throw |
|
Answer» Right choice is (b) arise an error To explain I would say: Because there is no way defined to catch that exception and as we know if an exception is not caught then error arises. |
|
| 140. |
What is the use of sort_heap() function in heap?(a) To sort the elements in the heap into descending order(b) To sort the elements in the heap into ascending order(c) To sort the first half of the heap(d) To sort the second half of the heap |
|
Answer» The correct answer is (b) To sort the elements in the heap into ascending order The explanation is: C++ STL-heap container provides sort_heap() function to sort the heap into ascending order which will no longer remain a heap. |
|
| 141. |
Which of the following is/are advantage(s) of Sequence Container arrays over C-like arrays?(a) Sequence Container arrays store its size within itself whereas C-like arrays do not(b) Sequence Container arrays are more efficient(c) Sequence Container arrays have no array decay problem whereas C-like arrays do have(d) All of the mentioned |
|
Answer» Correct choice is (d) All of the mentioned Easiest explanation - Sequence Container arrays(a.k.a Array classes) somehow stores its size and it can be implemented efficiently. Also, Array classes do not have Array decay problem. |
|
| 142. |
Which function is used to insert an element into heap?(a) push_back()(b) push_heap()(c) pop_back()(d) pop_heap() |
|
Answer» Correct choice is (b) push_heap() The best explanation: C++ STL-heap container provides push_heap() function that inserts a new element to the constructed heap. |
|
| 143. |
Which type of relationship is modelled by Composition?(a) Is-A relationship(b) Has-A relationship(c) Part-Of relationship(d) Have-A relationship |
|
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. |
|
| 144. |
What do you mean by “No exception specification”?(a) It throws nothing(b) It can throw anything(c) It can catch anything(d) It can try anything |
|
Answer» The correct choice is (b) It can throw anything For explanation: No exception specification that it can throw anything. |
|
| 145. |
Which of the following header file is needed to use vectors in your program?(a) (b) (c) (d) |
|
Answer» The correct option is (b) Explanation: Header file |
|
| 146. |
Pick the correct statement.(a) Vectors have dynamic size whereas Array classes have a static size(b) Both vectors and Array classes have a dynamic size(c) Both vectors and Array classes have a static size(d) Vectors have static size whereas Array classes have a dynamic size |
|
Answer» The correct choice is (a) Vectors have dynamic size whereas Array classes have a static size Explanation: Vectors are implemented in a way so that it can handle any number of elements at a time means the size of a vector can vary, whereas Array classes have fixed size. |
|
| 147. |
Sets are implemented using _______________________(a) binary search tree(b) red black tree(c) avl tree(d) heap |
|
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. |
|
| 148. |
Unordered map is implemented using _________________(a) binary search tree(b) red black tree(c) heap(d) hash table |
|
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. |
|
| 149. |
Where are standard exception classes grouped?(a) namespace std(b) error(c) catch(d) final |
|
Answer» Right answer is (a) namespace std Easiest explanation - As these are standard exceptions, they need to be defined in the standard block, So it is defined under namespace std. |
|
| 150. |
Pick out the correct statement for error handling alternatives.(a) Terminate the program(b) Use the stack(c) Exit from the block(d) Use the queue |
|
Answer» The correct answer is (b) Use the stack The best I can explain: When an error is raised means, it will be pushed into stack and it can be corrected later by the programmer. |
|