一个结构体的成员是另一个结构体
代码:
# 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-------- "); printf("Name:%s ",student.name); printf("Number:%d ",student.num); printf("Sex:%c ",student.sex); printf("Birthday:%d年%d月%d日 ",student.birthday.year,student.birthday.month,student.birthday.day); return 0; }
注意:因为birthday是另一个结构体变量,所以要使用大括号将赋值的数据包含在内