When you use aggregate initializers (initializers in {} ) in the "traditional" ANSI C language (C89 / 90), you must specify an individual initializer for each member of the structure in the order starting from the first. for example
struct S { int a, b, c, d; }; struct S s = { 1, 2, 3, 4 };
You do not have to specify initializers for all members, i.e. you can stop at any time (other members will be initialized to zeros).
If for some reason you just needed to explicitly initialize the third element of the structure, you had to provide explicit "dummy" initializers for the first and second members (just to get the right third)
struct S s = { 0, 0, 3 };
or completely abandon a specific initialization (most likely, replacing it with general = { 0 } ) and use the subsequent assignment to certain members
struct S s = { 0 }; sc = 3;
One of the notable advantages of this assignment-based approach is that it is independent of the position of the c member in the struct S declaration.
The new C language specification (C99) allows you to use initializers with a label by placing the desired member name in {}
struct S s = { .c = 3 };
Thus, you only explicitly initialize the required member (and have a compiler for zero initialization of the rest). This not only saves you from typing, but also makes aggregate initializers independent of the order in which members are specified in the structure type declaration.
Aggregate initializers, as you probably know, can also be used with arrays. And C99 supports "tagged" array initialization. What “tags” look like in case of an array is illustrated by the following example.
int a[10] = { [5] = 3 };
It is worth noting once again that the C language continues to adhere to the all-or-nothing approach for aggregation initialization: if you specify an explicit initializer for only one (or some) elements of a structure or array, the whole set is initialized, and members without explicit initializers get zero-initialization .