Toriyung

导航

关于struct和typedef

c/c++中有定义数据结构语句
struct student    //定义数据结构体
{
  int a;
  //.....    
}

struct student a1;    //初始化变量

可以看到,定义结构体后每次进行初始化时都需要带上"struct",较为冗余

解决方法是重定义类型typedef

//接上面代码

typedef struct student student_t;    //重定义为student_t
student_t a2;  //初始化变量

可以看到重定义后进行初始化变量时无需带上"struct"。

posted on 2022-10-28 22:50  Toriyung  阅读(16)  评论(0编辑  收藏  举报