ProgrammingModerateProduct-company placement · C++

Which line fails to compile (C++11 or later)?

Which line fails to compile (C++11 or later)?
int a(3.7);    // L1
int b = 3.7;   // L2
int c{3.7};    // L3
  1. A. L1 and L3
  2. B. L2 and L3
  3. C. L3 only
  4. D. None; all three store 3

Correct answer: C. L3 only

Brace (list) initialisation forbids narrowing conversions such as double to int, so L3 is ill-formed. Parentheses and = silently truncate to 3.

More OOP with C++ and Java questions

Exams that ask this topic