如何使用结构体中嵌套的结构体变量;
见代码块
#include <stdio.h>
?
int main(void)
{
//定义生日结构体;
struct Birthday{
? int year;
? int month;
? int day;
};
//定义个人信息结构体;
struct Person{
? ?
? ?float weight;
? ?
? ?float hight;
? ?
? ?float salary;
struct Birthday per_message;
};
//定义一个叫做Tom的人;
struct Person Tom;
Tom.weight=12.3;
Tom.hight=1.7;
Tom.salary=2000;
Tom.per_message.year=1999;
Tom.per_message.month=11;
Tom.per_message.day=1;
printf("Tom的体重是 %f \n", ?Tom.weight);
printf("Tom的身高是 %f m\n", Tom.hight);
printf("Tom的工资是 %f \n", ?Tom.salary);
printf("Tom是 %d年.%d月.%d日\n",Tom.per_message.year,Tom.per_message.month,Tom.per_message.day);
?
return 0;
}
讲解说明:
结构体内部逐步调用即可


运行效果如图:

|