C语言C语言知识库C++

C语言-typedef的用法

2018-07-24  本文已影响3人  黄一倚

普通用法:为数据类型取别名

typedef int Zhang;

以上语句表示:为int类型取一个名为Zhang的别名

int i;
Zhang i;

以上两条语句是等价的。

在结构体中的应用

typedef struct student{
    int sid;
    char[20] name;
}ST;

struct student st; 
//等价于
ST st;
typedef struct student{
    int sid;
    char[20] name;
}* PST;

struct student * st; 
//等价于
PST st;
typedef struct student{
    int sid;
    char[20] name;
}* PST, ST;   

PST 等价于 struct student *
ST   等价于 struct student
上一篇下一篇

猜你喜欢

热点阅读