What is the difference between int x = o and Int x{0}

closed account (EwCjE3v7)
What's the difference between int x= o and int x{0}
Thanks :D

Like this
1
2
3
long double ld = 3.1415926536;
 int a{ld}, b = {ld}; // error: narrowing conversion required 
int c(ld), d = ld;   // ok: but value will be truncated 


The compiler rejects the initializations of a and b because using a long double to initialize an int is likely to lose data. At a minimum, the fractional part of ld will be truncated. In addition, the integer part in ld might be too large to fit in an int
Last edited on
closed account (Dy7SLyTq)
{ld} is an initializer list. = ld is assignment and (ld) is a constructor
Topic archived. No new replies allowed.