DSP

为什么要用typedef定义结构体别名

2019-07-13 17:53发布

定义一个结构体,比如说:
struct STU
{
    int age;
    struct STU *next;
};
然后我想定义一个结构体类型的指针,应该是struct STU *p;或者定义一个普通的结构体变量struct STU a;
比较麻烦,用typedef后
typedef struct STU
{
    int age;
    struct STU *next;
}linklist;
那么现在linklist就代表这个结构体,现在定义结果提指针linklist *p;就方便了
同样,把他定义成
typedef struct STU
{
    int age;
    struct STU *next;
}*linklist;
那么linklist就是代表这个结构体指针类型,linklist head;head就是结构体指针类型了;