结构体变量的初始化
#include <stdio.h>
struct student
{
int num;
char name[20];
char sex;
int age;
float score;
};
int main()
{
struct student student1 = { 1001,"liming",'M',20,93.5 };
printf("The information of the student is :\n");
printf("num:%d\n", student1.num);
printf("name:%s\n", student1.name);
printf("sex:%c\n\n", student1.sex);
printf("age:%d\n", student1.age);
printf("score:%5.lf\n", student1.score);
}
初始化结构体数组
#include <stdio.h>
int main() {
struct student
{
int num;
char name[20];
float score;
}stu[5] =
{
{101,"黎明",89},
{102, "黎明2", 89},
{103,"黎明3",89},
{104, "黎明4", 89},
{105,"黎明5",89}
};
};