🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Iterators in C++: all 10 questions

Quiz: Iterators in C++ · Question 2 of 10

What does this print? (code)

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;
}
  1. A.15 10 3
  2. B.20 99 3
  3. C.20 99 2
  4. D.15 99 3
Answer & explanation

Correct answer: 20 99 3

it points to index 1 (changed to 99); it + 2 is index 3 (20); from index 1 to end is 3 steps.

Can you get the rest right without peeking?

Take the timed Quiz: Iterators in C++ quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →