c/language/array initialization

When an object of  type, the initializer must be either a  (optionally enclosed in braces) or be a brace-enclosed list of initialized for array members:

@1@ string literal initializer for character and wide character arrays @2@ comma-separated list of expressions that are initializers for array elements @3@ empty initializer empty-initializes every element of the array

Arrays of known size and arrays of unknown size may be initialized.

All array elements that are not initialized explicitly are.

Initialization from strings
(optionally enclosed in braces) may be used as the initializer for an array of matching type:
 * ordinary string literals can initialize arrays of any character type
 * L-prefixed wide string literals can be used to initialize arrays of any type compatible with (ignoring cv-qualifications) wchar_t

Successive bytes of the string literal or wide characters of the wide string literal, including the terminating null byte/character, initialize the elements of the array:

If the size of the array is known, it may be one less than the size of the string literal, in which case the terminating null character is ignored:

Note that the contents of such array are modifiable, unlike when accessing a string literal directly with.

Initialization from brace-enclosed lists
When an array is initialized with a brace-enclosed list of initializers, the first initializer in the list initializes the array element at index zero, and each subsequent initializer initializes the array element at index one greater than the one initialized by the previous initializer.

It's an error to provide more initializers than elements when initializing an array of known size (except when initializing character arrays from string literals).

When initializing an array of unknown size, the largest subscript for which an initializer is specified determines the size of the array being declared.

Nested arrays
If the elements of an array are arrays, structs, or unions, the corresponding initializers in the brace-enclosed list of initializers are any initializers that are valid for those members, except that their braces may be omitted as follows:

If the nested initializer begins with an opening brace, the entire nested initializer up to its closing brace initializes the corresponding array element:

If the nested initializer does not begin with an opening brace, only enough initializers from the list are taken to account for the elements or members of the sub-array, struct or union; any remaining initializers are left to initialize the next array element: