Home > Article > Backend Development > Can std::array be Default-Initialized?
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:
<code class="cpp">int plain_int{}; int c_style_array[13]{}; std::array<int, 13> cxx_style_array{};</code>
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.
The above is the detailed content of Can std::array be Default-Initialized?. For more information, please follow other related articles on the PHP Chinese website!