1. Home
  2. Computer Science MCQs
  3. C++ and Object-Oriented Programming
  4. For a std::deque, what is invalidated by a single…

Added 30 Nov -0001

For a std::deque, what is invalidated by a single push_front call?

  1. Nothing at all, because a deque never reallocates its element storage blocks
  2. References to existing elements, but the iterators remain valid instead
  3. Only iterators to the front element, since the rest of the blocks stay
  4. All existing iterators, though references to existing elements stay valid Correct answer

Correct answer

D. All existing iterators, though references to existing elements stay valid

21 views

MCQSEXAM

Explanation

std::deque stores elements in fixed-size blocks mapped by a central array, and inserting at either end may reallocate that map, invalidating every iterator while leaving references to existing elements intact. Insertion in the middle invalidates both iterators and references. This is why deque suits a queue well but is a poor choice when long-lived iterators must survive insertions.

Reference

Asked in: NTS, PPSC IT, Campus Interviews

Preparing for an exam?

Doubts & discussion

Not sure why the answer is D? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More C++ and Object-Oriented Programming MCQs

Practise all C++ and Object-Oriented Programming MCQs

Similar MCQs