typedef用法

typedef用法

——为数据类型起一个别名

——为了更加简洁和精炼

#include<stdio.h>
/*
typedef用法 
*/
typedef int Cmy;//为int 取一个别名 即Cmy等价于int 
typedef struct Student
{
	int sid;
	char name[100];
	char sex;
}St;//为struct Student 取一个别名St

typedef struct Student2
{
	int sid;
	char name[100];
	char sex;
}* PST,ST;
/*
PST等价于struct Student2 *   
ST等价于struct Student2 
*/
int main()
{
	int i = 10;
	Cmy j = 10;
	printf("%d-%d\n",i,j);
	struct Student st1;//等价于St st1 
	struct Student * pst = &st1; // 等价于St * pst 
	
	St st2;
	st2.sid = 1000;
	printf("%d\n",st2.sid);
	
	struct Student2 st3;
	PST ps = &st3;
	ps->sid = 99;
	printf("%d\n",st3.sid);
	
	ST st4;//struct Student2 st4
	PST pstu = &st4;//struct Student2 * pstu = &st4
	pstu->sid = 100;
	printf("%d\n",st4.sid);
	return 0;
	
	
}

image-20200608202719853

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值