← 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)?
- A.There is none
- B.at() is faster
- C.at() checks the index and throws out_of_range; s[i] does not check
- 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 →