c 语言 结构体的引用

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/luoganttcc/article/details/88616874
# 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

猜你喜欢

转载自blog.csdn.net/luoganttcc/article/details/88616874
今日推荐