typedef作用是为一种数据类型定义一个新名字
1.在单片机开发,寄存器为 8位,16位,32位
typedef unsigned char u_int8;//0~255
typedef unsigned short int u_int16;//0~65535
typedef unsigned int u_int32;//0~4,294,967,296
2.简化结构体
我们一般定义结构体:
struct student{
int score;
char *name;
};
一般实例化结构体:
struct student stu1;
//利用typedef后:
typedef struct Student{
int score;
char *name;
}student,*pstudent;
//因为在后面我们简化了名字,所以student可以去掉不写:
typedef struct{
int score;
char *name;
}student,*pstudent;
//但是在结构体里面要声明此结构体时还是要需要原来的样式:
typedef struct student{
int score;
char *name;
struct student* next;
}student,*pstudent;
//实例化结构体:
student stu1;//实例化结构体
student stu;//实例化结构体指针
//可见,加入typedef以后我们实例化结构体就更简洁!!!