ProgrammingModerateProduct-company placement · C++

What is printed?

What is printed?
int main() {
    vector<int> v{1, 2, 3, 2, 4};
    v.erase(remove(v.begin(), v.end(), 2), v.end());
    cout << v.size() << ":";
    for (int x : v) cout << x;
}
  1. A. 3:134
  2. B. 5:13424
  3. C. 4:1324
  4. D. 3:143

Correct answer: A. 3:134

remove shifts the kept elements to the front (order preserved) and returns the new logical end; erase then cuts off the leftover tail. remove alone never changes the size.

More OOP with C++ and Java questions

Exams that ask this topic