ProgrammingHardWipro Elite · TCS NQT Prime

What is printed? (C++17; assume <iostream>, <string>, <vector> and using namespace std)

What is printed? (C++17; assume <iostream>, <string>, <vector> and using namespace std)
int main() {
    vector<int> a(3, 1), b{3, 1};
    cout << a.size() << b.size() << b[0];
}
  1. A. 322
  2. B. 231
  3. C. 332
  4. D. 323

Correct answer: D. 323

Parentheses call the (count, value) constructor giving 3 elements; braces prefer the initializer_list giving {3, 1}: sizes 3 and 2, b[0] = 3.

More OOP with C++ and Java questions

Exams that ask this topic