创建结构体的三种方式及其使用

#include <stdio.h>
//创建结构体的第一种方式,推荐用这种 
struct Student1{
	int age; 
	float score;
	char sex; 
};
//创建结构体的第二种方式
struct Student2{
	int age;
	float score;
	char sex; 
}stu2; 
//创建结构体的第三种方式
struct {
	int age;
	float score;
	char sex; 
}stu3; 

void print(Student1 *stu){
	printf("%d %f %c\n",stu->age,stu->score,stu->sex); 
} 
void print(Student2 *stu){
	printf("%d %f %c\n",stu->age,stu->score,stu->sex); 
} 

void main(){
	struct Student1 stu1={12,12.2,'n'};
		print(&stu1); 
	struct Student2 *st=&stu2; 
	st->age=22;
	st->score=22.2;
	st->sex='n'; 
	//st->age 相当于 (*st).age 
		print(st);
	stu3.age=33;
	stu3.score=33.3;
	stu3.sex='v';
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值