Answer: Option C) increment it to move backward through the container
A reverse iterator is used to iterate backwards.
To iterate backwards use rbegin()
and rend()
as the iterators for the end of the collection, and the start of the collection respectively.
Incrementing a reverse_interator
moves it backward. We need to initialize it to rbegin()
Eg:-
for (vector<my_class>::reverse_iterator i = my_vector.rbegin();
i != my_vector.rend(); ++i ) {}
Iterating C++ vector from the end to the beginning - Stack Overflow