Initialization
Initialization means giving an object its first value when it is created.
int a; // default-initialization, no initial value
int b = 5; // copy-initialization
int c ( 6 ); // direct-initialization
int d { 7 }; // direct-list-initialization, preferred
int e {}; // value-initialization, usually 0 for int
int f = { 8 }; // copy-list-initialization, rarely used
For now I prefer brace initialization:
int x { 5 };
Avoid uninitialized variables:
int x; // local int has an indeterminate value
Safer:
int x {};
Braces block narrowing conversions:
int x { 4.5 }; // error
That is good. I want the compiler to complain before I accidentally turn 4.5 into 4 and pretend everything is fine.
When a variable will receive a value later, for example through std::cin, I still initialize it first:
int x {};
std::cin >> x;
Marking an intentionally unused variable:
[[maybe_unused]] int x { 5 };