InterviewSolution
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.
| 1. |
Which container is used to store elements as key-value pair?(a) map(b) multimap(c) unordered map(d) all of the mentionedThis question was addressed to me in final exam.The doubt is from More Containers in chapter Class Hierarchies, Library & Containers of C++ |
|
Answer» CORRECT choice is (d) all of the mentioned Easy EXPLANATION - C++ provides these three CONTAINERS(map, MULTIMAP and unordered map) to store ELEMENTS as key-value pair. |
|
| 2. |
In which of the following relationship objects of related classes are strongly dependent?(a) Aggregation(b) Association(c) Composition(d) Both Composition an AssociationI got this question in an online quiz.This interesting question is from Class Relationships in division Class Hierarchies, Library & Containers of C++ |
|
Answer» Correct choice is (d) Both COMPOSITION an ASSOCIATION |
|
| 3. |
Which of the following is corect way of constructing bitset using binary string?(a) bitset b;(b) bitset b(12);(c) bitset b(string(“1100”));(d) bitset b(float(12));This question was posed to me in an online quiz.This intriguing question comes from Bitset in chapter Class Hierarchies, Library & Containers of C++ |
|
Answer» CORRECT OPTION is (C) bitset Explanation: The correct way of constructing bitset using BINARY string is as follows: bitset |
|
| 4. |
What is the use of proj() function?(a) Used to calculate the argument of a complex number(b) Used to calculate the conjugate of a complex number(c) Used to calculate the negative of a complex number(d) Used to calculate the projection of a complex numberI have been asked this question by my school teacher while I was bunking the class.My doubt is from Complex Library in chapter Class Hierarchies, Library & Containers of C++ |
|
Answer» Correct CHOICE is (d) Used to calculate the projection of a COMPLEX number |
|
| 5. |
Which classes can have vtable?(a) Classes having friend functions(b) Classes having virtual functions(c) Classes having static functions(d) All classes have a vtableThe question was asked in a job interview.Query is from vtable and vptr in chapter Class Hierarchies, Library & Containers of C++ |
|
Answer» Correct CHOICE is (b) Classes having virtual FUNCTIONS |
|
| 6. |
Which function is used to insert an element into heap?(a) push_back()(b) push_heap()(c) pop_back()(d) pop_heap()This question was addressed to me in examination.This intriguing question originated from STL topic in division Class Hierarchies, Library & Containers of C++ |
|
Answer» Correct choice is (b) push_heap() |
|
| 7. |
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 sizeThis question was posed to me in unit test.I need to ask this question from seq_con Vector Class in portion Class Hierarchies, Library & Containers of C++ |
|
Answer» The correct choice is (a) Vectors have DYNAMIC SIZE whereas Array CLASSES have a static size |
|
| 8. |
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 mentionedThis question was posed to me by my school teacher while I was bunking the class.My question comes from seq_con Array Class in portion Class Hierarchies, Library & Containers of C++ |
|
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. |
|
| 9. |
What is mandatory for designing a new container?(a) Classes(b) Iterators(c) Container(d) VariablesThis question was addressed to me in homework.My question is taken from Defining a New Container in section Class Hierarchies, Library & Containers of C++ |
|
Answer» Right ANSWER is (b) ITERATORS |
|
| 10. |
Which are not full container classes in c++?(a) Sequence container(b) Associative container(c) Container adaptor(d) iterative containerThis question was posed to me in an interview.I'd like to ask this question from Almost Containers in division Class Hierarchies, Library & Containers of C++ |
|
Answer» CORRECT ANSWER is (c) Container adaptor Easy explanation - Container ADAPTORS are not full container classes, but classes that provide a specific INTERFACE relying on an object of one of the container classes such as deque or list to HANDLE the elements. |
|
| 11. |
What type of access does deque and vector provide?(a) Linear access(b) Parallel access(c) Random access(d) Memory accessThe question was asked during an interview.I need to ask this question from Almost Containers topic in chapter Class Hierarchies, Library & Containers of C++ |
|
Answer» RIGHT ANSWER is (C) Random access Explanation: Because they can manipulate the VALUES on anywhere in the program, So it is PROVIDING random access. |
|
| 12. |
Which symbol is used to create multiple inheritances?(a) Dot(b) Comma(c) Dollar(d) starThis question was posed to me in an international level competition.This interesting question is from Multiple Inheritance in division Class Hierarchies, Library & Containers of C++ |
|
Answer» CORRECT option is (b) COMMA The best I can explain: For USING MULTIPLE inheritance, simply specify each base class (just like in single inheritance), SEPARATED by a comma. |
|
| 13. |
Which of the following is correct about the map and unordered map?(a) Ordering of keys in maps whereas no such order in the unordered map(b) Maps are implemented red-black trees whereas unordered map are implemented using hash tables(c) Average search time in the unordered map is O(1) whereas it is O(logn) in case of maps(d) All of the mentionedThis question was posed to me in a national level competition.The query is from More Containers in portion Class Hierarchies, Library & Containers of C++ |
|
Answer» The CORRECT choice is (d) All of the mentioned |
|
| 14. |
Map is implemented using ____________________(a) binary search tree(b) red black tree(c) heap(d) hash tableThe question was asked during an interview for a job.My doubt stems from More Containers in section Class Hierarchies, Library & Containers of C++ |
|
Answer» Correct answer is (B) RED black tree |
|
| 15. |
Composition is a __________ type of Association relationship.(a) strong(b) weak(c) unnecessary(d) necessaryThis question was posed to me in an internship interview.The origin of the question is Class Relationships topic in chapter Class Hierarchies, Library & Containers of C++ |
|
Answer» Right option is (a) strong |
|
| 16. |
How the relationship is made in Association?(a) Through the objects of classes(b) Through constructor(c) Through destructor(d) Through class NamesThis question was addressed to me during an interview.My query is from Class Relationships topic in portion Class Hierarchies, Library & Containers of C++ |
|
Answer» The correct CHOICE is (a) Through the objects of classes |
|
| 17. |
What happens when only one argument is supplied to set() function?(a) All bits are set to 1 in a bitset(b) Bit corresponding to an argument is set to 1(c) All alternate bits are set to 1 in a bitset(d) First bit is set to 1I got this question during an online interview.My question is taken from Bitset in chapter Class Hierarchies, Library & Containers of C++ |
|
Answer» Correct answer is (b) Bit corresponding to an argument is SET to 1 |
|
| 18. |
What is bitset in C++?(a) An array of bools consuming one bit per element(b) Vector of bools(c) C-like arrays of bool elements(d) Template classI have been asked this question at a job interview.I'm obligated to ask this question of Bitset in chapter Class Hierarchies, Library & Containers of C++ |
|
Answer» Right choice is (a) An array of BOOLS consuming one bit per ELEMENT |
|
| 19. |
What are Engine Adaptors?(a) Class template that adopts a pseudo-random number generator engine(b) Class template that adopts a pseudo-random number generator engine to produce numbers with a given numbers of bits(c) Random number engine that generates pseudo-random numbers(d) Mersenne Twister 19937 generator generating 32-bit true random numberThe question was posed to me in an interview for job.This is a very interesting question from Generators in section Class Hierarchies, Library & Containers of C++ |
|
Answer» Right answer is (b) Class template that ADOPTS a pseudo-random NUMBER generator engine to produce numbers with a given numbers of bits |
|
| 20. |
Which type of heap is implemented in STL heap?(a) max heap(b) min heap(c) middle heap(d) close heapThis question was posed to me during an interview.My question is from STL in division Class Hierarchies, Library & Containers of C++ |
|
Answer» CORRECT ANSWER is (a) max heap Easiest explanation - C++ STL-heap implements max heap i.e. the front of heap CONTAINS the maximum of all the elements in a RANGE. |
|
| 21. |
What is a pair?(a) Container consisting of two data elements of the same type(b) Container consisting of two data elements of different type(c) Container consisting of one header and two data elements of the same type(d) Container consisting of two data elements can have the same or different typeI have been asked this question in an online interview.Enquiry is from STL topic in portion Class Hierarchies, Library & Containers of C++ |
|
Answer» The CORRECT choice is (d) Container CONSISTING of TWO data elements can have the same or different type |
|
| 22. |
What is the use of the allocator interface in the user-defined container?(a) Storage management(b) Memory management(c) Storage & Memory management(d) Iterator managementI have been asked this question in homework.The origin of the question is Defining a New Container topic in section Class Hierarchies, Library & Containers of C++ |
|
Answer» The CORRECT choice is (a) Storage management |
|
| 23. |
Where does the vector add the item?(a) End(b) Insert(c) Middle(d) StartI got this question in unit test.Asked question is from Almost Containers in section Class Hierarchies, Library & Containers of C++ |
|
Answer» Correct choice is (a) END |
|
| 24. |
How many types of class relationships are there?(a) 1(b) 2(c) 3(d) 4I got this question during an online exam.The above asked question is from Class Relationships topic in portion Class Hierarchies, Library & Containers of C++ |
|
Answer» The correct choice is (d) 4 |
|
| 25. |
How many ways are there for constructing a bitset?(a) 1(b) 2(c) 3(d) 4This question was posed to me by my school principal while I was bunking the class.My question is from Bitset topic in division Class Hierarchies, Library & Containers of C++ |
|
Answer» RIGHT choice is (c) 3 For EXPLANATION: There are three ways of constructing a bitset. Direct CONSTRUCTION, using integer number and using binary string. |
|
| 26. |
What is the use of rank() function in C++?(a) Returns size of each dimension(b) Returns how many total elements can be stored in an array(c) Returns how many elements are in array currently(d) Returns the dimension of an arrayThis question was addressed to me during an online exam.My doubt stems from Array Type Manipulation topic in portion Class Hierarchies, Library & Containers of C++ |
|
Answer» Correct OPTION is (d) Returns the DIMENSION of an ARRAY |
|
| 27. |
What is the default random engine?(a) Random number engine that generates pseudo-random numbers(b) Mersenne Twister 19937 generator generating 32-bit true random number(c) Random number engine that generates true random numbers(d) Mersenne Twister 19937 generator generating 32-bit pseudo random numberThe question was posed to me in homework.My question is based upon Generators in chapter Class Hierarchies, Library & Containers of C++ |
|
Answer» The CORRECT CHOICE is (a) RANDOM number engine that GENERATES pseudo-random numbers |
|
| 28. |
In how many different ways any-container can be constructed?(a) 1(b) 2(c) 3(d) 4The question was asked by my college professor while I was bunking the class.I would like to ask this question from STL Container Any in section Class Hierarchies, Library & Containers of C++ |
|
Answer» The CORRECT answer is (c) 3 |
|
| 29. |
How the list containers are implemented?(a) Using Double linked list(b) Using Single linked list(c) Using Single & Double linked list(d) Using linear linked listI got this question in an interview.I'm obligated to ask this question of Sequences in chapter Class Hierarchies, Library & Containers of C++ |
|
Answer» Correct answer is (a) Using Double linked LIST |
|
| 30. |
Which of the following describes the protected access specifier?(a) The variable is visible only outside inside the block(b) The variable is visible everywhere(c) The variable is visible to its block and to it’s derived class(d) The variable is not visible to its blockI have been asked this question during a job interview.My question is based upon Access Control in section Class Hierarchies, Library & Containers of C++ |
|
Answer» RIGHT choice is (c) The variable is visible to its block and to it’s derived class Best explanation: Protected members are visible to its block and to the derived CLASSES and not visible to OUTSIDE objects or VARIABLES. |
|
| 31. |
Which is the correct syntax of declaring a virtual function?(a) virtual int func();(b) virtual int func(){};(c) inline virtual func();(d) inline virtual func(){};The question was posed to me in an online quiz.This intriguing question comes from Inheritance topic in portion Class Hierarchies, Library & Containers of C++ |
|
Answer» The CORRECT answer is (a) virtual int func(); |
|
| 32. |
Which type of relationship is modelled by Aggregation?(a) Is-A relationship(b) Has-A relationship(c) Part-Of relationship(d) Have-A relationshipI had been asked this question in an international level competition.Query is from Class Relationships in division Class Hierarchies, Library & Containers of C++ |
|
Answer» The correct choice is (b) Has-A relationship |
|
| 33. |
Composition is also a type of _______________ relationship.(a) Aggregation(b) Association(c) Inheritance(d) Both Aggregation an AssociationI got this question in an internship interview.My query is from Class Relationships topic in division Class Hierarchies, Library & Containers of C++ |
|
Answer» RIGHT option is (B) Association The explanation: COMPOSITION is also a type of Both Aggregation and Association relationship. Composition RELATIONSHIPS are string relationships whereas others are a superset of this relationship. |
|
| 34. |
What is the use of reset 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 1(d) Used to make a bit(s) 0 in a bitsetThis question was addressed to me in an online interview.My query is from Bitset in section Class Hierarchies, Library & Containers of C++ |
|
Answer» The correct choice is (d) USED to make a bit(s) 0 in a BITSET |
|
| 35. |
What is the use of count() function in bitset?(a) To count the number of 0’s(b) To count the number of 1’s(c) To count the number of total bits in a bitset(d) To count the number of low bitsThis question was posed to me in an online interview.I'd like to ask this question from Bitset topic in section Class Hierarchies, Library & Containers of C++ |
|
Answer» Right choice is (B) To COUNT the number of 1’s |
|
| 36. |
Which of the following is correct about bitset and vector of bools?(a) Space consumed by bitset is less than vector(b) Bitset consume only 1 bit per element(c) Number of elements in bitset should be known at compile time whereas vector can have a dynamic size(d) All of the mentionedI have been asked this question in quiz.The origin of the question is Bitset in section Class Hierarchies, Library & Containers of C++ |
|
Answer» The correct option is (d) All of the mentioned |
|
| 37. |
Which function is used to calculate the norm of a complex number?(a) abs()(b) norm()(c) mod()(d) square_sum()This question was addressed to me in final exam.This intriguing question comes from Complex Library topic in portion Class Hierarchies, Library & Containers of C++ |
|
Answer» Right ANSWER is (b) norm() |
|
| 38. |
Which function is used to get the real part of the complex number?(a) img_p()(b) imag_p()(c) real()(d) real_p()I have been asked this question in an interview for internship.I would like to ask this question from Complex Library topic in division Class Hierarchies, Library & Containers of C++ |
|
Answer» Correct option is (c) real() |
|
| 39. |
What is random_device?(a) A pseudo-random number generator(b) Time-dependent random number generator(c) Simple random number generator(d) A true random number generatorI got this question in an online quiz.The origin of the question is Generators topic in chapter Class Hierarchies, Library & Containers of C++ |
|
Answer» The correct OPTION is (d) A true RANDOM NUMBER GENERATOR |
|
| 40. |
What is the difference between begin() and rbegin()?(a) both are the same(b) begin() returns an iterator to the first element and rbegin() returns an iterator to an element kept at the end of the vector(c) begin() returns an iterator to first element whereas rbegin() returns constant iterator to first element(d) begin() returns returns first element rbegin() returns voidI have been asked this question during a job interview.The origin of the question is seq_con Vector Class in section Class Hierarchies, Library & Containers of C++ |
|
Answer» Right choice is (b) BEGIN() returns an iterator to the first ELEMENT and rbegin() returns an iterator to an element kept at the end of the VECTOR |
|
| 41. |
How many items are there in sequence container?(a) 2(b) 3(c) 4(d) 5I got this question during an interview.My enquiry is from Sequences topic in division Class Hierarchies, Library & Containers of C++ |
|
Answer» The correct choice is (d) 5 |
|
| 42. |
How many sets of requirements are need in designing a container?(a) 1(b) 2(c) 3(d) 4This question was posed to me in a job interview.The above asked question is from Container Design in division Class Hierarchies, Library & Containers of C++ |
|
Answer» Correct OPTION is (c) 3 |
|
| 43. |
Which is the correct syntax of constructing a bitset?(a) bitset b;(b) bitset b(12);(c) bitset b(string(“1100”));(d) all of the mentionedI had been asked this question in final exam.I'd like to ask this question from Bitset in chapter Class Hierarchies, Library & Containers of C++ |
|
Answer» Correct answer is (d) all of the MENTIONED |
|
| 44. |
Which of the following is the limitation of bitset over vector bool?(a) Space(b) Size(c) Type(d) SpeedThe question was asked in final exam.My question is from Bitset in section Class Hierarchies, Library & Containers of C++ |
|
Answer» The CORRECT option is (b) Size |
|
| 45. |
What is the use of is_array() function in C++?(a) To check if a variable is array type or not(b) To check if a variable is 1-D array type or not(c) To check if a variable is 2-D array type or not(d) To check if a variable is 1-D or 2-D array type or notThis question was posed to me in semester exam.My question is taken from Array Type Manipulation in section Class Hierarchies, Library & Containers of C++ |
|
Answer» The CORRECT option is (a) To CHECK if a variable is array type or not |
|
| 46. |
What is mersenne_twister_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 asked in an international level competition.Question is taken from Generators in chapter Class Hierarchies, Library & Containers of C++ |
|
Answer» Correct option is (b) Pseudo-random NUMBER ENGINE that generates random unsigned INTEGERS in the range [0, 2^W-1] for some w using Mersenne Twister algorithm |
|
| 47. |
What are Distributions in C++?(a) Objects that converts a sequence into a sequence having an ascending order(b) Objects that converts a sequence into a sequence having specific random variable distribution(c) Objects that converts a sequence into a sequence having a descending order(d) Objects that converts a sequence into a sequence having only the smallest, largest and medianI got this question in quiz.Enquiry is from Generators in chapter Class Hierarchies, Library & Containers of C++ |
|
Answer» Right option is (b) Objects that converts a sequence into a sequence having specific RANDOM VARIABLE distribution |
|
| 48. |
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 heapThe question was asked in an online quiz.This question is from STL in portion Class Hierarchies, Library & Containers of C++ |
|
Answer» The correct ANSWER is (b) To sort the ELEMENTS in the heap into ascending order |
|
| 49. |
Which of the following header file is needed to use vectors in your program?(a) (b) (c) (d) I have been asked this question by my college professor while I was bunking the class.I want to ask this question from seq_con Vector Class in chapter Class Hierarchies, Library & Containers of C++ |
|
Answer» The CORRECT option is (b) |
|
| 50. |
What are the vectors?(a) Arrays with dynamic size(b) Arrays with different types of elements(c) Same as array classes(d) Arrays with static size but use template classesI had been asked this question in an online quiz.This interesting question is from seq_con Vector Class topic in portion Class Hierarchies, Library & Containers of C++ |
|
Answer» The CORRECT OPTION is (a) ARRAYS with dynamic size |
|