# include <stdio.h>
# include <stdlib.h>
// 定义结构体
struct tagPoint
{
double x;
double y;
double z;
}tagPoint;
// 给tagPoint起别名Point
typedef struct tagPoint Point;
// 定义了一个tagPoint类型指针
typedef struct tagPoint *PNode;
// 也可以二合一写法
// typedef struct tagPoint
// {
// double x;
// double y;
// double z;
// } Point;
int main(){
Point p = {100, 100, 0};
printf("%f
",p.x);
// sizeof里面的结构体必须是别名
PNode p1 = (PNode)malloc(sizeof(tagPoint));
(*p1).x = 32.0;
printf("%f
",(*p1).x);
return 0;
}
【C】C语言typedef
“年轻时,我没受过多少系统教育,但什么书都读。读得最多的是诗,包括烂诗,我坚信烂诗早晚会让我邂逅好诗。”
by. 马尔克斯