作用:用于建立新的数据类型名,也就是给现有的数据类型取个别名
typedef 数据类型名 数据类型别名;
- 之后就可以使用数据类型别名来替换数据类型名来使用
- 这种一般就是给现有数据类型名取个自己容易一眼看懂的名字
代码示例
#include <stdio.h>
int main(int argc, char const *argv[])
{
struct point{
int x;
int y;
};
typedef struct point point; //以后的point就表示struct point
point p1; //使用新声明的类型别名point来声明变量
point *ps = &p1;
ps -> x = 1;
ps -> y = 2;
printf("point is (%d, %d)\n", ps -> x, ps -> y);
return 0;
}
运行结果:
point is (1, 2)