LearnFrenzy
Sign in Take a free test

STL Algorithms and Iterators · STL Algorithms MCQ · Question 6

Why does std::remove not shrink a vector? Answer, explanation & discussion

  • MCQ
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 6 Back to Exercise

After std::remove(v.begin(), v.end(), 0), why is v.size() unchanged?

  • A remove is broken
  • B Algorithms work through iterators and cannot change a container's size; call v.erase(result, v.end()) Correct
  • C remove only works on lists
  • D It removes nothing
Correct Answer: Option B

C++20 std::erase(v, 0) does both steps.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links