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;
}