← All topics
Quiz: Iterators in C++: questions with answers
10 questions, each with the answer and a short explanation.
Take the timed quiz + get a certificate →- Q1. What does v.end() point to?
- Q2. What does this print? (code)
- Q3. For a map<string,int iterator it, how do you read the value (not the key)?
- Q4. Why does sort(myList.begin(), myList.end()) fail to compile for a std::list?
- Q5. Which loop correctly removes all even numbers from a vector v while iterating?
- Q6. What does this print? (code)
- Q7. Why can pushback on a vector make an old iterator into it unsafe?
- Q8. What kind of iterator do cbegin() and cend() return?
- Q9. What does the erase–remove idiom v.erase(removeif(v.begin(), v.end(), pred), v.end()) gain over erasing one element at a time?
- Q10. Which container keeps iterators to other elements valid when you insert or erase?