When you write struct Yin this context
struct X {
struct Y {
int z;
} y;
} x;
you do two things:
- Define
struct Yand - Add a
ytype field struct Yinside struct X.
struct, , . struct , struct country .
, , :
struct country westpark;
strcpy(westpark.countryname, "Germany");
strcpy(westpark.state.statename, "Bavaria");
strcpy(westpark.state.city.cityname, "Ingolstadt");
strcpy(westpark.state.city.shop.shopname, "Westpark");
, . , - :
struct country {
char countryname[100];
struct state {
char statename[100];
struct city {
char cityname[100];
int postal;
struct shop {
char shopname[100];
} shop[MAX_SHOP];
int shopCount;
} city[MAX_CITY];
int cityCount;
} state[MAX_STATE];
int stateCount;
} country;
, , , - . , .. stateCount , state[] , cityCount state[] city[], ..
struct 50 , : , -, 50 - . struct:
strcpy(country.countryname, "Germany");
country.stateCount = 1;
strcpy(country.state[0].statename, "Bavaria");
country.state[0].cityCount = 1;
strcpy(country.state[0].city[0].cityname, "Ingolstadt");
country.state[0].city[0].shopCount = 1;
strcpy(country.state[0].city[0].shop[0].shopname, "Westpark");
, , . , state[], , city[], , , . , .