C 语言变量初始化

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/luoganttcc/article/details/88616955
# include <stdio.h>
# include <string.h>
struct AGE
{
    int year;
    int month;
    int day;
};
struct STUDENT
{
    char name[20];  //姓名
    int num;  //学号
    struct AGE birthday;  /*用struct AGE结构体类型定义结构体变量birthday, 即生日*/
    float score;  //分数
};
int main(void)
{
    struct STUDENT student1;  /*用struct STUDENT结构体类型定义结构体变量student1*/
    strcpy(student1.name, "小明");  //不能写成&student1
    student1.num = 1207041;
    student1.birthday.year = 1989;
    student1.birthday.month = 3;
    student1.birthday.day = 29;
    student1.score = 100;
    printf("name : %s\n", student1.name);  //不能写成&student1
    printf("num : %d\n", student1.num);
    printf("birthday : %d-%d-%d\n", student1.birthday.year, student1.birthday.month, student1.birthday.day);
    printf("score : %.1f\n", student1.score);
    return 0;
}

name : 小明
num : 1207041
birthday : 1989-3-29
score : 100.0

猜你喜欢

转载自blog.csdn.net/luoganttcc/article/details/88616955