首页 > 代码库 > 结构体嵌套

结构体嵌套


#include <stdio.h>

int main()
{
    typedef  struct date{
        int year;
        int mouth;
        int day;
    }Date;
    typedef  struct student{
        int age;
        Date birthday;
        Date inday;
    }Student;
    Student stu ={23,{1991,1,1},{2011,1,1}};
    Student *p;
    p = &stu;
    printf("%d,%d,%d\n",stu.age,stu.birthday.mouth,stu.inday.day);
    printf("%d,%d,%d\n",(*p).birthday.year,(*p).birthday.mouth,(*p).birthday.day);
    printf("%d,%d,%d\n",p->birthday.year,p->birthday.mouth,p->birthday.day);
    
    return 0;
}

结构体嵌套