C语言 包含结构的结构

  一个结构体的成员是另一个结构体

代码:

# include <stdio.h>
# include <stdlib.h>

struct data
{
    int year;
    int month;
    int day;
};

struct student
{
    char name[30];
    int num;
    char sex;
    struct data birthday;
}student = {"dire",2017,'W',{1990,1,6}};

int main ()
{
    printf("--------Information--------\n");
    printf("Name:%s\n",student.name);
    printf("Number:%d\n",student.num);
    printf("Sex:%c\n",student.sex);
    printf("Birthday:%d年%d月%d日\n",student.birthday.year,student.birthday.month,student.birthday.day);
        
    return 0;
} 

注意:因为birthday是另一个结构体变量,所以要使用大括号将赋值的数据包含在内

posted @ 2016-02-28 13:56  dire  阅读(548)  评论(0编辑  收藏  举报