Initialization
From cppreference.com
Initialization of a variable provides its initial value at the time of construction.
The initial value may be provided in the initializer section of a declarator. It also takes place during function calls: function parameters and the function return values are also initialized.
For each declarator, the initializer may be one of the following:
( Template:sparam )
|
(1) | ||||||||
= Template:sparam
|
(2) | ||||||||
{ Template:sparam }
|
(3) | ||||||||
1) comma-separated list of arbitrary expressions in parentheses
2) the equals sign followed by an expression
3) braced-init-list: possibly empty, comma-separated list of expressions and other braced-init-lists
Depending on context, initializer may invoke one of the following:
- Value initialization, e.g. std::string s{};;
- Direct initialization, e.g. std::string s("hello");
- Copy initialization, e.g. std::string s = "hello";
- List initialization, e.g. std::string s{'a', 'b', 'c'};
- Aggregate initialization, e.g. char a[3] = {'a', 'b'};
- Reference initialization, e.g. char& c = a[0];
If no initializer is provided, the rules of default initialization apply.
When certain conditions are met, initialization of static and thread-local objects may be executed as constant initialization.