ProgrammingVery hardProduct-company placement · C++

What is printed?

What is printed?
struct W {
    W(int, int)                { cout << "2"; }
    W(initializer_list<int>)   { cout << "L"; }
};
int main() { W a(1, 2); W b{1, 2}; }
  1. A. 22
  2. B. 2L
  3. C. LL
  4. D. L2

Correct answer: B. 2L

With braces, a constructor taking initializer_list is strongly preferred whenever it is viable; parentheses use ordinary overload resolution and pick W(int, int).

More OOP with C++ and Java questions

Exams that ask this topic