🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← 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?

  1. A.Nothing
  2. B.Doubles every element of v in place
  3. C.Creates a new doubled vector
  4. 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 →