typedef struct
程序员文章站
2024-03-23 14:16:40
...
typedef struct MyStruct
{
int a;
float b;
}TagStruct;
相当于以下两步:
struct MyStruct
{
int a;
float b;
};
typedef /*struct(可省略)*/ MyStruct TagStruct;
当然也可以改为指针的形式
typedef struct MyStruct
{
int a;
float b;
}*TagStruct;
但是这样需要为用TagStruct定义的结构体变量开辟空间才能继续使用:
int main(){
TagStruct myStruct;
myStruct = (tagStruct)malloc(sizeof(*myStruct));
myStruct->a = 1;
myStruct->b = 2;
}