【C】C语言typedef

# 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\n",p.x);

    // sizeof里面的结构体必须是别名
    PNode p1 = (PNode)malloc(sizeof(tagPoint));
    (*p1).x = 32.0;
    printf("%f\n",(*p1).x);

    

    return 0;
}

猜你喜欢

转载自www.cnblogs.com/jzsg/p/10947450.html