ProgrammingModerateMicrosoft/Google SDE MCQ · GATE CS

What is printed?

What is printed?
int main() {
    vector<int> a(3, 5);
    vector<int> b{3, 5};
    vector<int> c;
    c.reserve(10);
    cout << a.size() << b.size() << c.size();
}
  1. A. 3210
  2. B. 320
  3. C. 220
  4. D. 3010

Correct answer: B. 320

(3, 5) means three elements equal to 5. Braces prefer the initializer_list constructor, giving the two elements 3 and 5. reserve only changes capacity, so c.size() stays 0.

More OOP with C++ and Java questions

Exams that ask this topic