An example to study scope & designated initializer

struct Point4D
{
int x;
int y;
int z;
int w;
} A={.y=5,15};
int main(){
printf("\nThe 4D point A is (%d,%d,%d,%d).",A.x,A.y,A.z,A.w);
struct Point4D B ={10,20};
printf("\nThe 4D point B is (%d,%d,%d,%d).",B.x,B.y,B.z,B.w);
struct Point3D
{
int x;
int y;
int z;
} A={.y=5,15}; //No other local A so no error
printf("\nThe 3D point A is (%d,%d,%d).",A.x,A.y,A.z);
//struct Point3D B ={10}; //Error because there is a local B
struct Point3D C ={10};
printf("\nThe 3D point C is (%d,%d,%d).",C.x,C.y,C.z);
struct Point4D D ={.w = 10,.z = 5, 15}; //w is after z so 15 overwrites 10
printf("\nThe 4D point D is (%d,%d,%d,%d).",D.x,D.y,D.z,D.w);
}
Output:


