初遇结构体

初遇结构体

#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)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值