🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Memory and Smart Pointers: all 10 questions

Quiz: Memory and Smart Pointers · Question 10 of 10

Which exception does vector::at(i) throw when i is outside the vector?

Which exception does vector::at(i) throw when i is outside the vector?

  1. A.invalid_argument
  2. B.bad_alloc
  3. C.out_of_range
  4. D.runtime_error
Answer & explanation

Correct answer: out_of_range

at() checks the index and throws out_of_range; operator[] does not check at all.

Can you get the rest right without peeking?

Take the timed Quiz: Memory and Smart Pointers quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →