🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← 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 →
  1. Q1. What does v.end() point to?
  2. Q2. What does this print? (code)
  3. Q3. For a map<string,int iterator it, how do you read the value (not the key)?
  4. Q4. Why does sort(myList.begin(), myList.end()) fail to compile for a std::list?
  5. Q5. Which loop correctly removes all even numbers from a vector v while iterating?
  6. Q6. What does this print? (code)
  7. Q7. Why can pushback on a vector make an old iterator into it unsafe?
  8. Q8. What kind of iterator do cbegin() and cend() return?
  9. 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?
  10. Q10. Which container keeps iterators to other elements valid when you insert or erase?