Default Initialization in std::array
Default initialization is the initialization that occurs when no explicit initializer is provided. With C 11 std::array, the syntax std::array
According to the C 11 standard (§8.5/11), any object without an explicit initializer is default initialized. This includes std::array objects and traditional C-style arrays. Notably, default initialization has no effect on non-class, non-array types, leaving their value indeterminate.
Value Initialization on All Arrays
While default initialization leaves non-class, non-array types indeterminate, value initialization sets elements to their default values. In C 11, value initialization is achieved by providing an empty initializer for each array element:
int plain_int{}; int c_style_array[13]{}; std::array<int, 13> cxx_style_array{};
This will value-initialize all elements of the arrays, resulting in plain_int and all array elements being initialized to zero.
The above is the detailed content of How Does Default Initialization Work with `std::array` in C 11?. For more information, please follow other related articles on the PHP Chinese website!