“要成为绝世高手,并不是一朝一夕,除非是天生武学奇才,可是这种人…万中无一”
编程
做者数组
闫小林微信
白天搬砖,晚上作梦。我有故事,你有酒么?app
例37:C语言实现把一个学生的信息(包括学号、姓名、姓名、地址)放在一个结构体变量中。而后输出这个学生的信息。
函数
#include<stdio.h>//头文件
int main()//主函数
{
struct student_Information //定义学生结构体
{
int num; //学号
char name[20];//名字
char sex[20];//性别
char address[20]; //地址
}
student_Information={8888,"闫小林","男生","广州市"};//赋值
printf("学号是:%d\n",student_Information.num);//输出学号
printf("姓名是:%s\n",student_Information.name);//输出名字
printf("性别是:%s\n",student_Information.sex);//输出性别
printf("住址是:%s\n",student_Information.address);//输出住址
return 0;//主函数返回值为0
}
学号是:8888
姓名是:闫小林
性别是:男生
住址是:广州市
--------------------------------
Process exited after 2.791 seconds with return value 0
请按任意键继续. . .
%s
学号是:8888
姓名是:?
性别是:?
住址是:?
--------------------------------
Process exited after 1.785 seconds with return value 0
请按任意键继续. . .
本文分享自微信公众号 - C语言入门到精通(c_printf)。
若有侵权,请联系 support@oschina.cn 删除。
本文参与“OSC源创计划”,欢迎正在阅读的你也加入,一块儿分享。工具