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

Quiz: Strings in C++ · Question 7 of 10

What is the difference between s[i] and s.at(i)?

What is the difference between s[i] and s.at(i)?

  1. A.There is none
  2. B.at() is faster
  3. C.at() checks the index and throws out_of_range; s[i] does not check
  4. D.s[i] works only on const strings
Answer & explanation

Correct answer: at() checks the index and throws out_of_range; s[i] does not check

A bad index with [] is undefined behaviour; at() reports it.

Can you get the rest right without peeking?

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

Start the quiz →