構造体を、別の構造体のメンバにすることもできる。これを「構造体のネスト」あるいは「ネストした構造体(nested structure)」と呼ぶ。
次の例は、10 人の作業員を配置する製造ラインの情報を格納するために、構造体をネストしている。
#define NUM_ON_LINE 10
struct worker {
char name[80];
int avg_units_per_hour;
int avg_errs_per_hour;
};
struct asm_line {
int product_code;
double material_cost;
struct worker wkers[NUM_ON_LINE];
} line1, line2;
製造ライン line1 の構造体配列 wkers の 2 番目の様相のメンバ avg_units_per_hour に値 12 を代入するには次のようにする。
line1.wkers[1].avg_units_per_hour = 12;
要は外から順にたどっていけばいい。