C++20 sections · 1024 units
Open in Course

Partial Initialization

When you provide fewer values

When you provide fewer initializers than the array size, C++ fills remaining elements with zeros. Declare int arr[5] = {1, 2}; and you get {1, 2, 0, 0, 0}. The rest become zero automatically.

This zero-filling is guaranteed by the language standard. It's not garbage; it's always exactly zero for numeric types. Partial initialization is safe and predictable. A common pattern: int arr[100] = {0}; creates 100 zeros.

You provide one zero, and the rest fill in. This is cleaner than looping to zero out each element.