ProgrammingHardProduct-company placement · C++

What is printed?

What is printed?
int main() {
    vector<int> a(3, 5), b{3, 5};
    cout << a.size() << a[0] << b.size() << b[0];
}
  1. A. 3535
  2. B. 2323
  3. C. 3523
  4. D. 3553

Correct answer: C. 3523

Parentheses select the (count, value) constructor: three 5s. Braces prefer the initializer_list constructor: the two elements 3 and 5.

More OOP with C++ and Java questions

Exams that ask this topic