#include <stdio.h>
int main(int argc,const char*argv[]){
struct Time{
int hour;
int min;
int sec;
};
struct Data{
int year;
int month;
int day;
struct Time time;
};
struct Student{
char *name;
int age;
float score;
struct Data birthday;
//struct Student stu;该句式是错误的,不可以嵌套
//struct Student *stu;该句式正确,可以嵌套
};
//(1)嵌套的结构体如何进行初始化
struct Student stu1={"张三丰",28,59.99f,
{1200,12,12,{12,12,12}}};定义一个结构体变量
//(2)嵌套的结构体如何进行访问
printf("姓名:%s,年龄:%d(生日:%d-%02d-%02d %02d:
%02d:%02d),成绩:%.2f
\n",stu1.name,stu1.age,stu1.birthday.year,stu1.birthd
ay.month,stu1.birthday.day,stu1.birthday.time.hour,st
u1.birthday.time.min,stu1.birthday.time.sec,stu1.scor
e);
return 0;
} |
|