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

Quiz: Iterators in C++ · Question 4 of 10

Why does sort(myList.begin(), myList.end()) fail to compile for a std::list?

Why does sort(myList.begin(), myList.end()) fail to compile for a std::list?

  1. A.list elements cannot be compared
  2. B.sort needs random-access iterators, but list iterators are only bidirectional
  3. C.list has no begin() function
  4. D.sort only works on arrays
Answer & explanation

Correct answer: sort needs random-access iterators, but list iterators are only bidirectional

Use the member function myList.sort() for lists.

Can you get the rest right without peeking?

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

Start the quiz →