Consider three arrays initialized with different forms: `double A[] = { 7.8, };`, `double B[3] = { 2 * A[0], 7, 33, };`, and `double C[] = { [0] = 6, [3] = 1, };`. Each object groups several component objects, while its initializer assigns values to those components. Such grouped C types are aggregate data types. section 5.5
Arrays combine items with one base type; structures combine items that may have different base types. Unions group differently typed members over the same memory location, but their treatment requires a deeper memory-model discussion. Aggregate initialization follows declaration order when designators are omitted, and omitted members receive default initialization. section 6.0 section 5.5
Key rules make aggregate initialization predictable:
- Prefer designated initializers such as `[3] = 1` or `.member = value`; they remain more robust when declarations change. section 5.5
- Use `{0}` as a catch-all initializer for every non-variable-length object type; the first component receives zero and the remaining components default to zero. section 5.5
double A[] = { 7.8, };
double B[3] = { 2 * A[0], 7, 33, };
double C[] = { [0] = 6, [3] = 1, };
!@%STYLE%@!
{"css":"{\"css\": \"font-weight: bold;\"}","target":"[[{\"line\":0,\"ch\":0},{\"line\":0,\"ch\":6}],[{\"line\":1,\"ch\":0},{\"line\":1,\"ch\":6}],[{\"line\":2,\"ch\":0},{\"line\":2,\"ch\":6}],[{\"line\":0,\"ch\":0},{\"line\":0,\"ch\":6}],[{\"line\":1,\"ch\":0},{\"line\":1,\"ch\":6}],[{\"line\":2,\"ch\":0},{\"line\":2,\"ch\":6}],[{\"line\":0,\"ch\":0},{\"line\":0,\"ch\":6}],[{\"line\":1,\"ch\":0},{\"line\":1,\"ch\":6}],[{\"line\":2,\"ch\":0},{\"line\":2,\"ch\":6}]]"}
!@%STYLE%@!
Compare inferred array length, positional initialization, and designated array elements in a compact code listing. section 5.5
