C语言结构体嵌套

#include <stdio.h>

int main()
{
    /***************************************************
     *结构体嵌套:结构体里面包含结构体
     *
     *注意:被包含的结构体要先定义,结构体不能包含自己
     ****************************************************/
     struct Date
     {
         int year;
         int month;
         int day;
     };
     struct Student
     {
         int no;
         struct Date birthday;
     };
     struct Student student =
     {
             1,
             {1989, 2, 4}
     };
     printf("no = %d, birthday = %d年%d月%d日 \n", student.no,
               student.birthday.year, student.birthday.month, student.birthday.day);
     return 0;
}
no = 1, birthday = 1989年2月4日 

 

posted @ 2014-01-23 12:30  天之涯0204  阅读(377)  评论(0编辑  收藏  举报