初遇结构体
#include<stdio.h>
int main()
{
typedef struct student
//声明一个结构体类型student
{
long studentID;
char studentName[10];
char studentSex;
int yearofBirth;
int score[4];
}STUDENT;
//利用typedef 取一个别名STUDENT ,STUDENT为一个结构体类型 (像数组一样)
STUDENT stu1 = {2020211903,"王二",'M',2002,{72,80,110,20}};//定义一个结构体
printf("%d/%s/%c/%d\n%d/%d/%d/%d\n",stu1.studentID,
stu1.studentName, //使用结构体内定义的数据,需要加上 <结构体名.数据名> ,另外注意字符型数组的引用,只需要写出数组名
stu1.studentSex,
stu1.yearofBirth,
stu1.score[0],
stu1.score[1],
stu1.score[2],
stu1.score[3]);//printf的输出可以分行
return 0;
}
关于typedef的介绍可以访问(https://blog.csdn.net/liitdar/article/details/80069638)