Test Series - cpp

Test Number 89/102

Q: 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 classes
Solution: Iterators are STL components used to point a memory address of a container. They are used to iterate over container classes.
Q: Which function is used increment the iterator by a particular value?
A. next()
B. advance()
C. prev()
D. move()
Solution: advance() function is used to increment an iterator by a given value.
Q: How many types of Iterators are there?
A. 5
B. 2
C. 3
D. 4
Solution: 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.
Q: 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 downwards
Solution: By definition Input iterators moves sequentially forward.
Q: 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 operators
Solution: Values cannot be assigned to the location pointed by input operators. Input operators cannot be used with all relational and arithmetic operators.
Q: 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 mentioned
Solution: Input iterators can only be incremented and as it cannot be decremented it can be used in single-pass algorithms only.
Q: 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 assigning
Solution: Input Iterators are used for accessing and Output Iterators are used for assigning.
Q: 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 also
Solution: 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.
Q: 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 sides
Solution: Bi-directional iterator is a type of forward iterators that can be used for both directions access and assign.
Q: What are Random-access Iterators?
A. Iterators that can be used to access elements at an arbitrary offset position
B. Same as Bi-directional iterator
C. Input iterator with the additional property of random access
D. Output iterator with the additional property of random access
Solution: Random access iterators are those iterators that can be used to access elements at an arbitrary offset position relative to the memory that the iterator points.

You Have Score    /10