Can std::array be Default-Initialized?
By declaring a variable as std::array
However, you should be aware that default initialization has no effect on non-class, non-array types (§8.5/6), leaving their values indeterminate. For example, a default-initialized array of such types will have indeterminate values.
Value-Initialization of Arrays
If you wish to initialize all array elements to a specific value T{}, this is not default-initialization but value-initialization (8.5/7). You can value-initialize arrays easily in C 11 by using empty initializers:
int plain_int{};
int c_style_array[13]{};
std::array cxx_style_array{};
This will value-initialize all array elements, resulting in a consistent value of 0 for integers and the default values for their respective data types.
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3