示例1:
#include<stdio.h>
//typedef int ZHANGSAN;// 为int 再多取一个名字 ,ZHANGSAN等价于 int
typedef struct Student
{
int sid;
char name[100];
char sex;
}ST;//其实就是相当于 给 struct Student再起了一个名字
int main(void)
{
int i = 10;//等价于ZHANGSAN i = 10;
ZHANGSAN J =20;
struct Student st;//等价于 ST st;
struct Student * ps = &st;//等价于ST * ps;
ST st2;
ST *ps2 = &st2;
return 0;
}
示例2:
#include<stdio.h>
typedef struct Student
{
int sid;
char name[100];
char sex;
}* PST;
/*
PST 等价于 struct Student *
可以将
typedef struct Student
{
int sid;
char name[100];
char sex;
}* 看作一个数据类型
*/
int main(void)
{
struct Student st;
PST ps = &st;
ps->sid = 99;
printf("%d\n",ps->sid);
return 0;
}
示例3:
#include<stdio.h>
typedef struct Student
{
int sid;
char name[100];
char sex;
}* PST,STU; //等价于STU代表了 struct Student,PST 代表了 struct Student *;
int main(void)
{
STU stu;//相当于 struct Student stu;
PST ps = &stu;//就相当于 struct Student * ps;
ps->sid = 99;
printf("%d\n",ps->sid);
return 0;
}