Which header must be included to use iterators with STL containers in C++?
Analysis & Theory
<iterator> provides definitions for iterator types and utilities.
Which function returns an iterator to the beginning of a container?
Analysis & Theory
The `begin()` function returns an iterator to the first element of a container.
Which of the following denotes the end of a container in C++?
Analysis & Theory
`end()` returns an iterator pointing past the last element, not the last element itself.
What is the type of an iterator for a `vector<int>` container?
Analysis & Theory
Correct syntax is `vector<int>::iterator` for declaring an iterator for a vector of ints.
Which iterator allows read-only access to container elements?
Analysis & Theory
`const_iterator` allows traversal but does not allow modifying the element.
Which of the following is NOT a valid iterator operation?
Analysis & Theory
`it+*` is invalid. Iterators can be incremented, dereferenced, or decremented (for bidirectional/ random-access iterators).
What will `*vec.begin()` return for a vector<int> vec = {1, 2, 3};?
Analysis & Theory
`*vec.begin()` dereferences the iterator to get the first element, which is 1.
Which iterator can be used to traverse a container in reverse order?
Analysis & Theory
STL containers provide `rbegin()` and `rend()` for reverse iteration using `reverse_iterator`.
Which of these containers support random-access iterators?
Analysis & Theory
`vector` and `deque` support random-access iterators. `list` only supports bidirectional iterators.
What does `std::advance(it, 3)` do?
B
Moves iterator forward by 3 positions
C
Sorts the container from it to it+3
Analysis & Theory
`std::advance(it, n)` advances the iterator `it` by `n` steps.