Namespaces
Variants
Views
Actions

Initialization

From cppreference.com
< cpp‎ | language
Revision as of 06:39, 25 March 2013 by Cubbi (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
 
 
C++ language
General topics
Flow control
Conditional execution statements
if
Iteration statements (loops)
for
range-for (C++11)
Jump statements
Functions
Function declaration
Lambda function expression
inline specifier
Dynamic exception specifications (until C++17*)
noexcept specifier (C++11)
Exceptions
Namespaces
Types
Specifiers
const/volatile
decltype (C++11)
auto (C++11)
constexpr (C++11)
consteval (C++20)
constinit (C++20)
Storage duration specifiers
Initialization
Expressions
Alternative representations
Literals
Boolean - Integer - Floating-point
Character - String - nullptr (C++11)
User-defined (C++11)
Utilities
Attributes (C++11)
Types
typedef declaration
Type alias declaration (C++11)
Casts
Memory allocation
Classes
Class-specific function properties
explicit (C++11)
static

Special member functions
Templates
Miscellaneous
 

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:

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.