typedef是类型定义的意思。
typedef struct 是为了使用这个结构体方便。
typedef的用法
typedef unsigned int uint_32;
将unsigned int 重命名为uint_32, 所以uint_32也是一个类型名
具体区别在于:
若struct node{ }这样来定义结构体的话。在定义 node 的结构体变量时,需要这样写:struct node n;
若用typedef,需要这样写:typedef struct node{}NODE; 。在申请变量时就只用写成:NODE n;其实就相当于 NODE 是struct node 的别名。区别就在于使用时,是否可以省去struct这个关键字。
.
.
.
.
例子
struct Student
{
int no;
char name[12];
}stu1;//s**tu1是一个创建的全局变量**
typedef struct Student2
{
int no;
char name[12];
}stu2;//stu2是一个结构体(数据)类型
在申请结构体变量时
struct Student wj={0};
stu2 wj={0};
很明显下面的方法要简单清晰许多