Home > Article > Backend Development > How is Default Initialization Handled for `std::array` in C 11?
Default initialization, performed when no explicit initializer is specified, is guaranteed by the C language standard for all objects without an explicit initializer, including instances of std::array
However, it's important to note that default initialization has no effect on non-class, non-array types, leaving their value indeterminate (§8.5/6). For example, a default-initialized array of such types will have indeterminate values:
<code class="cpp">int plain_int; int c_style_array[13]; std::array<int, 13> cxx_style_array;</code>
To explicitly initialize all elements to T{}, use value-initialization (8.5/7):
<code class="cpp">int plain_int{}; int c_style_array[13]{}; std::array<int, 13> cxx_style_array{};</code>
The above is the detailed content of How is Default Initialization Handled for `std::array` in C 11?. For more information, please follow other related articles on the PHP Chinese website!