int i{0}; //(1)
int i = 0; //(2)
Do I have correct understanding that in first case (1) the variable i will be created already with 0 as it's value, and in (2) it will be created without a value and then assigned a value 0, so (1) will always faster then (2)?
But seems like most(all?) modern compilers will still optimize (2) to be same as (1) under the hood?
CodePudding user response:
initializing variables with Brace Initialization performs additional checks at compile time (no effect on runtime). . Such as if you enter a float literal inside the curly braces it will throw an error. Initialization with the equal sign will be optimized by the compiler. Prefer brace initialization whenever possible. I hope that answers your question