Array initialization
From cppreference.com
When initializing an object of array type, the initializer must be either a string literal (optionally enclosed in braces) or be a brace-enclosed list of initialized for array members:
= string-literal
|
(1) | ||||||||
= { expression , ... }
|
(2) | (until C99) | |||||||
= { designator(optional) expression , ... }
|
(2) | (since C99) | |||||||
= { }
|
(3) | (since C23) | |||||||
1) string literal initializer for character and wide character arrays
2) comma-separated list of constant(until C99) expressions that are initializers for array elements, optionally using array designators of the form
[
constant-expression ]
=
(since C99)3) empty initializer empty-initializes every element of the array
Arrays of known size and arrays of unknown size may be initialized, but not VLAs(since C99)(until C23). A VLA can only be empty-initialized.(since C23)
All array elements that are not initialized explicitly are empty-initialized.
Contents |