1 嵌套的结构体如何进行初始化
struct Student stu1 = {"zhangsanfeng",25,59.99f,{1200,12,12}};//定义一个结构体变量
2 嵌套的结构体如何访问
printf("姓名:%s,年龄:%d,生日:%d-%02d-%02d,成绩:%.2f",stu1.name,stu1.age,stu1.birthday.year,stu1.birthday.month,stu1.birthday.day,stu1.score);
2) 结构体嵌套自己的指针
struct Person{
char *name;
int age;
//嵌套自己类型指针
struct Person *child;
};
//定义 Kim
struct Person kim ={"kim",8 ,NULL};
struct Person p1 = {"linzhiying",38,&kim};
//结构体嵌套自身指针的访问
printf("%s的儿子是:%s,儿子的年龄:%d\n",p1.name,p1.child->name,p1.child->age);
或者是 printf("%s的儿子是:%s,儿子的年龄:%d\n",p1.name,(*p1.child).name,(*p1.child).age); |
|