← Quiz: C++ Introduction: all 10 questions
Quiz: C++ Introduction · Question 5 of 10
What does for (auto& x : v) x = 2; do?
What does for (auto& x : v) x *= 2; do?
- A.Nothing
- B.Doubles every element of v in place
- C.Creates a new doubled vector
- D.Causes a compile error
Answer & explanation
Correct answer: Doubles every element of v in place
The & makes x a reference to each element, so changes apply to v.
Can you get the rest right without peeking?
Take the timed Quiz: C++ Introduction quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →