首页 > 其他分享 >关于struct和typedef

关于struct和typedef

时间:2022-10-28 23:01:36浏览次数:44  
标签:初始化 typedef 定义 关于 student 变量 struct

c/c++中有定义数据结构语句

struct student    //定义数据结构体
{
  int a;
  //.....    
}

struct student a1;    //初始化变量

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

解决方法是重定义类型typedef

//接上面代码

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

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

标签:初始化,typedef,定义,关于,student,变量,struct
From: https://www.cnblogs.com/toriyung/p/16837761.html

相关文章