All challenges
Multiple ChoiceIntermediate 45s

Narrowing conversion in braces

Why does `int x{2.5};` fail to compile but `int x = 2.5;` compile (with a warning)?
Options
  1. 1Braces convert 2.5 to the nearest integer, and the compiler rejects that as an ambiguity.
  2. 2Both forms fail to compile; the premise is wrong because both reject the conversion.
  3. 3List-initialization forbids narrowing conversions; copy-initialization only warns.
  4. 4Braces interpret the literal 2.5 as a string, which cannot initialize an int at all.

Think you can answer under pressure?

Get matched and answer live questions in 3-minute 1v1 battles. Elo ranking, badge tiers and bragging rights on the line.

Play this in a 3-minute battle