typedef
作用:为一种数据类型定义一个新名字。
1.和普通类型匹配,通过名字来获取一些信息。一般配寄存器中会用到。
例如:
typedef unsigned char u_int8; //(0,255) 8位寄存器
typedef unsigned short int u_int16; // 16位寄存器
typedef unsigned int u_int32; // 32位寄存器
//通过typedef 把类型直接命名为u_int8等。代码比较友好。比较直观和方便省事
2.和struct 搭配使代码更简洁。
typedef struct student
{
char name;
int chengji;
}STU,*PSTU; // 用typedef 把struct student 命名为STU
//也可以命名指针 可以同时使用。
int main()
{
STU t1;
t1.chengji=100;
printf("chengji:%d\n",t1.chengji);
PSTU T2;
T2=(PSTU)malloc(sizeof(STU));
T2->chengji=99;
printf("chengji:%d\n",T2->chengji);
return 0;
}