Skills101
← All practice quizzes

Quiz: Iterators in C++

5 questions · new set on every retakeNo time limitPass: 60%+10 XP on first pass

Iterators are how C++ walks through any container and how STL algorithms work on all of them. Learn begin and end, dereferencing, reverse and const iterators, the iterator categories, next, advance and distance, and how to erase safely while looping.

Log in to take the quiz

Free account · see your score, answers and explanations, earn XP

  1. Question 1

    What does v.end() point to?

  2. Question 2

    What does this print?

    #include <iostream>
    #include <vector>
    using namespace std;
    int main() {
        vector<int> v = {5, 10, 15, 20};
        auto it = v.begin() + 1;
        *it = 99;
        cout << *(it + 2) << " " << v[1] << " " << (v.end() - it) << "\n";
        return 0;
    }
    
  3. Question 3

    For a map<string,int> iterator it, how do you read the value (not the key)?

  4. Question 4

    Why does sort(myList.begin(), myList.end()) fail to compile for a std::list?

  5. Question 5

    Which loop correctly removes all even numbers from a vector v while iterating?

🎯 Today’s placement challenge — 10 questions, no login. Can you score 10/10?Take today’s challenge →