← 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;
}
- A.15 10 3
- B.20 99 3
- C.20 99 2
- 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 →