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.

1.

What is the correct function prototype of () operator overloading?(a) return_type operator(arguments)();(b) return_type operator(arguments);(c) return_type operator()(arguments);(d) return_type operator(Class_name)(arguments);I have been asked this question in quiz.I need to ask this question from Functors topic in chapter Algorithms, Objects & Iterators in C++ of C++

Answer»

Right option is (C) return_type operator()(arguments);

The explanation: The CORRECT SYNTAX of OVERLOADING a () operator in a class is as follows:

return_type operator()(arguments){}

2.

Which header file is used to manipulate the allocater?(a) allocater(b) memory(c) object(d) iteratorThis question was posed to me during a job interview.My enquiry is from Allocators topic in division Algorithms, Objects & Iterators in C++ of C++

Answer»

The CORRECT option is (b) memory

Best explanation: Because all the memory ALLOCATION and deallocation LIBRARIES are DECLARED in .

3.

Which function is used to return the minimum element in the range?(a) min(b) minimum(c) min_element(d) max_elementThe question was posed to me in an online quiz.The query is from Min and Max topic in portion Algorithms, Objects & Iterators in C++ of C++

Answer»

Correct choice is (C) min_element

The explanation is: The min_element is USED to compare the range of elements and it can FIND out the MINIMUM ELEMENT.

4.

Which value is pointed out first in heap?(a) Lowest value(b) Highest value(c) First value(d) Third valueThis question was addressed to me in homework.This interesting question is from Heaps in portion Algorithms, Objects & Iterators in C++ of C++

Answer»

Correct OPTION is (b) Highest value

The explanation is: The ELEMENT with the highest value is ALWAYS POINTED by first.

5.

What kind of execution does sequence point allow?(a) Non-overlap(b) Overlap(c) Concurrent(d) SequenceI got this question during an interview.Origin of the question is Stored Sequences topic in division Algorithms, Objects & Iterators in C++ of C++

Answer»

The CORRECT OPTION is (a) Non-overlap

Explanation: To resolve all the side-effects in the program, the sequence point should not be OVERLAPPED.

6.

Which of the following is a logical unary functor?(a) logical_or f;(b) logical_and f;(c) logical_not f;(d) negate f;The question was asked during an online exam.Origin of the question is Functors in chapter Algorithms, Objects & Iterators in C++ of C++

Answer»

The correct choice is (c) logical_not f;

To EXPLAIN I would say: logical_and and logical_or requires two ARGUMENTS to act upon whereas negate and logical_not requires only ONE argument but negate also produces non-logical results like negate of a NUMBER, therefore, it is not logical hence logical_not f; is an only logical functor.

7.

What are functors in C++?(a) Objects of a class which are treated as functions(b) Objects that are used to call the function of other classes(c) Functions that are called using pointer objects(d) Functions that are called only once in a programThis question was posed to me during an interview for a job.The origin of the question is Functors topic in portion Algorithms, Objects & Iterators in C++ of C++

Answer»

Correct choice is (a) Objects of a class which are treated as functions

Explanation: FUNCTORS are objects of a class that are treated like function i.e. they can ALSO be USED as function calls.

8.

Which of the following can serve as random-access iterator?(a) Memory pointer(b) Object pointer(c) Class pointer(d) Memory & Class pointerI got this question by my college director while I was bunking the class.My question comes from Iterators and Sequences topic in division Algorithms, Objects & Iterators in C++ of C++

Answer»

The correct answer is (B) Object pointer

The best explanation: Because of this, It can SERVE as any CATEGORY of ITERATOR.

9.

What type of algorithm is not available in creating our own STL style algorithms?(a) copy_if()(b) remove_copy_if()(c) sort(d) remove_copy()I had been asked this question in quiz.This intriguing question originated from C Style Algorithms topic in division Algorithms, Objects & Iterators in C++ of C++

Answer»

Correct CHOICE is (a) copy_if()

To explain: copy_if() ALGORITHM is not AVAILABLE in CREATING our own STL style algorithms.

10.

Which of the following is correct?(a) Input Iterators are used for assigning(b) Output Iterators are used for assigning(c) Both Input and Output Iterators are used for accessing(d) Both Input and Output Iterators are used for assigningThe question was asked in unit test.Question is taken from Iterators in chapter Algorithms, Objects & Iterators in C++ of C++

Answer»

The correct answer is (B) OUTPUT Iterators are used for ASSIGNING

Easiest explanation - INPUT Iterators are used for ACCESSING and Output Iterators are used for assigning.

11.

Which of the following header file is required to use in-bulit functors of C++?(a) (b) (c) (d) The question was posed to me during an internship interview.This interesting question is from Functors topic in portion Algorithms, Objects & Iterators in C++ of C++

Answer»

Right choice is (b)

Best EXPLANATION: header file is REQUIRED to USE the fuctionality of in-built FUNCTORS provided by C++.

12.

How many parameters are needed for minmax function?(a) 1(b) 2(c) 3(d) All of the mentionedThe question was posed to me in an online interview.This question is from Min and Max in portion Algorithms, Objects & Iterators in C++ of C++

Answer»

The correct choice is (d) All of the mentioned

The BEST explanation: The “MINMAX” function can take the following:

1 PARAMETER: An initializer_list object.

2 parameters: Values to COMPARE.

2 parameters: An initializer_list object. and comparison function

3 parameters: Values to compare. and comparison function

13.

Where are allocators used?(a) Allocation of memory(b) Deallocation of memory(c) Used for pointers(d) Both Allocation & Deallocation of memoryThis question was addressed to me by my college professor while I was bunking the class.My question is from Allocators in portion Algorithms, Objects & Iterators in C++ of C++

Answer»

Correct option is (d) Both ALLOCATION & Deallocation of memory

Easiest explanation - Allocators HANDLE all the request for allocation and deallocation of memory for the CONTAINER.

14.

How many ways are there to use functors?(a) 1(b) 2(c) 3(d) 4The question was posed to me in my homework.Asked question is from Functors in division Algorithms, Objects & Iterators in C++ of C++

Answer»

The CORRECT option is (b) 2

Explanation: There are two WAYS of using functors ONE like function calls and other like normal CLASS OBJECTS.

15.

What are binary functors?(a) Functors that accepts only one parameter(b) Functors that accepts more than one parameters(c) Functors that accepts two parameters(d) Functors that accepts other than a specific type of parameterI had been asked this question in semester exam.I'm obligated to ask this question of Functors in portion Algorithms, Objects & Iterators in C++ of C++

Answer»

The CORRECT choice is (c) FUNCTORS that accepts two parameters

To EXPLAIN: Binary functors are those which accepts two ARGUMENTS as a parameter in a functor.

16.

How many categories of iterators are there in c++?(a) 2(b) 4(c) 5(d) 3The question was asked during an interview.This is a very interesting question from Iterators and Sequences topic in section Algorithms, Objects & Iterators in C++ of C++

Answer» RIGHT OPTION is (c) 5

Easiest EXPLANATION - There are FIVE types of iterators. They are Output, Input, Forward, Random ACCESS and Bi-directional.
17.

Pick out the in correct type of function in header file.(a) Partitions(b) Sort(c) Merge(d) JoinI got this question in an interview for internship.Asked question is from C Style Algorithms topic in portion Algorithms, Objects & Iterators in C++ of C++

Answer»

Right answer is (d) Join

Explanation: First THREE type of OPTIONS are AVAILABLE in HEADER FILE.

18.

Which of the following operators are overloaded for functors?(a) [](b) ()(c) This question was addressed to me in an interview for internship.My question is from Functors in division Algorithms, Objects & Iterators in C++ of C++

Answer»

Right ANSWER is (B) ()

The explanation is: () operator is overloaded to use functor PROPERTY in a C++ PROGRAM because this is the only operator used for a function call.

19.

Which operator is used to deallocate the memory?(a) destroy(b) free(c) empty(d) insertThis question was posed to me in an online interview.I want to ask this question from Allocators topic in chapter Algorithms, Objects & Iterators in C++ of C++

Answer»

Right ANSWER is (B) FREE

The best I can explain: free operator is used to deallocate the MEMORY.

20.

What is the use of checked iterators?(a) Overwrite the bounds of your container(b) Not allow you to overwrite the bounds of your container(c) It will check the list value(d) Overwrite the bounds of your iteratorsThis question was addressed to me in final exam.My query is from Checked Iterators in section Algorithms, Objects & Iterators in C++ of C++

Answer»

The correct OPTION is (b) Not allow you to OVERWRITE the bounds of your CONTAINER

Explanation: Checked ITERATORS ensure that you do not overwrite the bounds of your container.

21.

How many types of Iterators are there?(a) 5(b) 2(c) 3(d) 4I got this question in an international level competition.My question is from Iterators topic in section Algorithms, Objects & Iterators in C++ of C++

Answer»

The correct OPTION is (a) 5

Best explanation: There are 5 types of ITERATORS discussed under STL NAMELY:

i) Input Iterators

ii) Output Iterators

iii) Forward Iterators

iv) Bi-directional Iterators

v) Random-access Iterators.

22.

Which keyword is used to declare the min and max functions?(a) iostream(b) string(c) algorithm(d) iteratorThe question was posed to me in semester exam.Origin of the question is Min and Max topic in chapter Algorithms, Objects & Iterators in C++ of C++

Answer» RIGHT ANSWER is (c) algorithm

The explanation: Algorithm header FILE contains the supporting files needed for the EXECUTION of these functions.
23.

In sequence point, how will the overloaded operators behave like?(a) Function(b) Objects(c) Instance variable(d) ContainerThe question was asked during an interview.This intriguing question originated from Stored Sequences topic in section Algorithms, Objects & Iterators in C++ of C++

Answer»

Correct CHOICE is (a) FUNCTION

For EXPLANATION: In SEQUENCE POINT, the overloaded operators behave like a function.

24.

In which type of semantics does c++ implements iterator?(a) Memory(b) Size(c) Pointer(d) ValueI have been asked this question during an online exam.The query is from Iterators and Sequences in section Algorithms, Objects & Iterators in C++ of C++

Answer»

The CORRECT choice is (c) POINTER

The explanation: C++ USES pointer arithmetic/semantic to IMPLEMENT iterators.

25.

Which of the following is correct about Functors?(a) Functors should not be declared outside the main function(b) Overloaded operator () function is not a member of the class(c) Functors should be declared global(d) Functors have a stateI have been asked this question in unit test.This key question is from Functors in section Algorithms, Objects & Iterators in C++ of C++

Answer»

The correct choice is (d) Functors have a state

The EXPLANATION is: Functors are objects of a class which ALSO have other members and MEMBER functions which can be used to save states of that functors hence functors have a state. Functors can be declared anywhere in a PROGRAM.

26.

Which of the following is correct about Input Iterators?(a) They cannot be decremented(b) Cannot be used in multi-pass algorithms(c) Can only be incremented(d) All of the mentionedI had been asked this question during an interview.This intriguing question originated from Iterators in portion Algorithms, Objects & Iterators in C++ of C++

Answer»

The CORRECT OPTION is (d) All of the mentioned

Best EXPLANATION: Input ITERATORS can only be incremented and as it cannot be decremented it can be used in single-pass algorithms only.

27.

How many adaptors support the checked iterators?(a) 1(b) 2(c) 3(d) 4I had been asked this question in exam.I need to ask this question from Checked Iterators in portion Algorithms, Objects & Iterators in C++ of C++

Answer» RIGHT choice is (B) 2

The BEST I can EXPLAIN: There are two adaptors that SUPPORT checked iterators. They are checked_array_iterator class, Checked_iterator class.
28.

Which operator is used to allocate the memory?(a) =(b) +(c) new(d) freeI have been asked this question in an interview.I need to ask this question from Allocators topic in section Algorithms, Objects & Iterators in C++ of C++

Answer» CORRECT OPTION is (c) new

To EXPLAIN I would say: The default allocator uses operator new to allocate memory.
29.

What is the use of includes function in c++?(a) Compares two ranges of data(b) Compares two sorted ranges of data(c) Includes a new element in the range(d) Includes a new element in the endThis question was posed to me in class test.This interesting question is from C Style Algorithms topic in section Algorithms, Objects & Iterators in C++ of C++

Answer»

Right answer is (b) Compares TWO sorted ranges of data

To explain I would say: RETURNS true if the FIRST sorted RANGE contains all the elements in the second sorted range.

30.

In what form does the STL provides heap?(a) queue(b) list(c) vector(d) priority_queueThis question was posed to me by my school teacher while I was bunking the class.Query is from Heaps topic in section Algorithms, Objects & Iterators in C++ of C++

Answer»

The CORRECT choice is (d) priority_queue

The best explanation: STL does provide a HEAP in the FORM of a std::priority_queue.

31.

What is meant by heap?(a) Used for fast retrieval of elements(b) Used for organising the elements(c) Used for fast retrieval & organising the elements(d) Used for deleting the elementsThis question was posed to me by my school teacher while I was bunking the class.My question is taken from Heaps topic in chapter Algorithms, Objects & Iterators in C++ of C++

Answer»

Right OPTION is (c) Used for fast RETRIEVAL & organising the elements

To EXPLAIN I WOULD SAY: A heap is a way to organize the elements of a range that allows for fast retrieval of the element.

32.

Which of te following is a built-in example of functors in C++?(a) mltiplication f(a1, a2);(b) add f(a1, a2);(c) subtract f(a1, a2);(d) plus f(a1, a2);I had been asked this question in my homework.I'm obligated to ask this question of Functors topic in portion Algorithms, Objects & Iterators in C++ of C++

Answer» RIGHT choice is (d) PLUS F(A1, a2);

The BEST explanation: plus f(a1, a2); is one of the correct in-built functor available.
33.

Which of the following is correct about Input Iterators?(a) Input iterators can be used with all relational operators(b) Input iterators can work with arithmetic operators(c) No value can be assigned to the location pointed by Input Iterator(d) Input iterators can work with sequence operatorsI had been asked this question in homework.This interesting question is from Iterators topic in portion Algorithms, Objects & Iterators in C++ of C++

Answer»

The CORRECT option is (c) No value can be assigned to the location pointed by INPUT Iterator

To explain: VALUES cannot be assigned to the location pointed by input OPERATORS. Input operators cannot be used with all relational and arithmetic operators.

34.

What does the checked iterator allow you to find?(a) Warnings(b) Compile time error(c) Run time error(d) Warnings & Run time errorThe question was asked in an interview.My query is from Checked Iterators topic in portion Algorithms, Objects & Iterators in C++ of C++

Answer» RIGHT choice is (C) RUN time ERROR

Explanation: Checked iterator allow you to FIND Run time error.
35.

Which function is used increment the iterator by a particular value?(a) next()(b) advance()(c) prev()(d) move()I have been asked this question in an international level competition.This key question is from Iterators topic in section Algorithms, Objects & Iterators in C++ of C++

Answer»

Correct OPTION is (b) advance()

The best I can explain: advance() FUNCTION is USED to increment an iterator by a given value.

36.

What are Iterators?(a) STL component used to point a memory address of a container(b) STL component used for vectors(c) STL component used to call functions efficiently(d) STL component used to define template classesI had been asked this question in semester exam.Query is from Iterators topic in portion Algorithms, Objects & Iterators in C++ of C++

Answer» CORRECT answer is (a) STL component used to point a MEMORY address of a container

The best explanation: ITERATORS are STL components used to point a memory address of a container. They are used to ITERATE over container classes.
37.

What is the use of reference member type in allocator?(a) Point to an element(b) Quantities of element(c) Reference to an element(d) Sequence of an elementThe question was asked in unit test.I want to ask this question from Allocators in chapter Algorithms, Objects & Iterators in C++ of C++

Answer»

The CORRECT answer is (c) Reference to an element

The BEST I can EXPLAIN: free() function is used to free the memory used by the program.

eg,

int *p = (int*) MALLOC(sizeof(int));//ALLOCATION of memory.

free(p);// freeing the memory occupied by pointer p.

38.

What are unary functors?(a) Functors that accepts only one parameter(b) Functors that accepts two parameters(c) Functors that accepts more than one parameters(d) Functors that accepts other than a specific type of parameterThis question was posed to me by my school teacher while I was bunking the class.This interesting question is from Functors topic in division Algorithms, Objects & Iterators in C++ of C++

Answer»

Right choice is (a) FUNCTORS that accepts only ONE PARAMETER

For EXPLANATION: Unary functors are those which accepts only one ARGUMENT as a parameter in a functor.

39.

What are Bi-directional iterators?(a) Iterator same as Forward Iterator(b) Forward Iterator that can be used in both directions(c) Iterator that can only be used to access the sequence from both sides(d) Iterator that can only be used to assign the sequence from both sidesThe question was asked in unit test.The query is from Iterators topic in division Algorithms, Objects & Iterators in C++ of C++

Answer»

Right option is (B) Forward Iterator that can be used in both directions

The BEST I can EXPLAIN: Bi-directional iterator is a type of forward ITERATORS that can be used for both directions access and assign.

40.

Pick the correct statement.(a) Input iterator moves sequentially forward(b) Input iterator moves sequentially backward(c) Input iterator moves in both direction(d) Input iterator moves sequentially downwardsThis question was addressed to me during an interview for a job.Origin of the question is Iterators topic in portion Algorithms, Objects & Iterators in C++ of C++

Answer» RIGHT answer is (a) INPUT iterator moves sequentially FORWARD

Explanation: By definition Input ITERATORS moves sequentially forward.
41.

What kind of pattern is iterator pattern?(a) Design pattern(b) Sequence pattern(c) Adapter pattern(d) Star patternThis question was addressed to me during an online interview.I would like to ask this question from Iterators and Sequences in division Algorithms, Objects & Iterators in C++ of C++

Answer»

Right CHOICE is (a) Design pattern

Explanation: Iterator pattern is a design pattern in which an iterator is used to traverse a CONTAINER and access the container’s ELEMENTS.

42.

What is meant by hash tables in C++?(a) Array data structure(b) Keyed array data structure(c) Data structure(d) Linear probingThis question was addressed to me in examination.My doubt is from C Style Algorithms topic in portion Algorithms, Objects & Iterators in C++ of C++

Answer»

Right ANSWER is (b) KEYED ARRAY data structure

The BEST I can explain: In HASH table, every value will have a key, So that it can be accessed easily.

43.

What will happen if the iterator is unchecked?(a) Arising of compiler warnings(b) Unchecked behavior on program(c) Nothing will execute(d) Arising of compiler warnings & Unchecked behavior on programThis question was posed to me in exam.Origin of the question is Checked Iterators in portion Algorithms, Objects & Iterators in C++ of C++

Answer»
44.

Which operator is used to compare the elements in heap?(a) >>(b) comp(c)

Answer»

Correct option is (d) Both comp &<

For explanation: The elements in the heap are compared using operator< (for the FIRST version), or comp (for the second version).

45.

Where are allocators implemented?(a) Template library(b) Standard library(c) C++ code library(d) String libraryI have been asked this question during an internship interview.My question is from Allocators in chapter Algorithms, Objects & Iterators in C++ of C++

Answer»

Right choice is (b) STANDARD library

Best explanation: Allocators are IMPLEMENTED in C++ standard library but it is used for C++ template library.

46.

Which of the following is an advantage of Forward iterator over input and output iterator?(a) Can be used as both accessing and assigning iterator(b) Forward iterator can be incremented or decremented(c) Can be used with relational operators also(d) Can be used with arithmetic operators alsoThis question was posed to me in an interview.The origin of the question is Iterators topic in section Algorithms, Objects & Iterators in C++ of C++

Answer»

Correct option is (a) Can be USED as both accessing and assigning ITERATOR

To explain: FORWARD iterator is a combination of both input and output iterator, therefore, can be used as both accessing and assigning iterator. Just like Input and output iterator this can also be not used with all relational and arithmetic OPERATORS and can be incremented only.

47.

What kind of functions are min and max in c++?(a) Type specific(b) Variable specific(c) Type & Variable specific(d) IteratorI had been asked this question in an internship interview.I'm obligated to ask this question of Min and Max topic in division Algorithms, Objects & Iterators in C++ of C++

Answer»

Correct ANSWER is (a) TYPE specific

The best explanation: The min/max functions are type specific but they will not force EVERYTHING to be converted to/from FLOATING point. The functions that will force everything to be converted to/from floating point are fmin/fmax.

48.

What do input and output objects support?(a) Terminated sequences(b) Extracted sequences(c) Null-terminated sequences(d) Terminated & Extracted sequencesI got this question in final exam.This interesting question is from Stored Sequences in section Algorithms, Objects & Iterators in C++ of C++

Answer»

The correct choice is (C) Null-terminated sequences

The best I can explain: cin and cout SUPPORT null-terminated sequences as valid CONTAINERS for sequences of characters.

49.

How to protect the heap from affecting the memory?(a) Avoid using pointers for associating two data structures(b) Embed pointed child objects into the parent object(c) Allocate objects in chunks(d) All of the mentionedThis question was posed to me in homework.Question is from Heaps in chapter Algorithms, Objects & Iterators in C++ of C++

Answer»

The correct option is (d) All of the mentioned

For explanation: STEPS to protect the heap from affecting the memory.

-> Avoid using POINTERS for associating two data structures

-> Embed pointed child OBJECTS into the PARENT OBJECT

-> Allocate objects in chunks.

50.

Pick out the correct statement about sequence point.(a) Sequence point will compile the program(b) Sequence point will resolve all the side effects(c) Sequence point will save the program for execution(d) Sequence point will delete the program for executionI have been asked this question in an online quiz.This intriguing question originated from Stored Sequences topic in division Algorithms, Objects & Iterators in C++ of C++

Answer»

Correct choice is (B) Sequence point will resolve all the side EFFECTS

The explanation is: Sequence point is a point in TIME at which the dust has settled and all side effects which have been seen so far are guaranteed to be complete.