c 语言 结构体的引用

时间:2023-01-13 07:18:35


# include <stdio.h>
struct AGE
{
int year;
int month;
int day;
};
struct STUDENT
{
char name[20];
int num;
struct AGE birthday; //就有点类似于C++中的封装了
float score;
};
int main(void)
{
struct STUDENT student1 = {"小明", 1207041, {1989, 3, 29}, 100};
printf("name : %s\n", student1.name);
printf("birthday : %d-%d-%d\n", student1.birthday.year, student1.birthday.month, student1.birthday.day);
printf("num : %d\n", student1.num);
printf("score : %.1f\n", student1.score);
return 0;
}
name : 小明
birthday : 1989-3-29
num : 1207041
score : 100.0