typedef struct 与 struct
使用typedef定义结构体时,它就是类型定义的意思。主要是为了方便才使用typedef,在申请变量时可直接写例如:t_student student;
使用struct定义构体时,只是在申请变量时,需要加上struct t_student student
举例说明
/* 声明st_student 结构体 */
typedef struct st_student
{
char name[64];
int age;
}t_student;
/* 申请结构体变量 */
t_student student;
/* 声明st_student 结构体 */
struct st_student
{
char name[64];
int age;
};
/* 申请结构体变量 */
struct t_student student; //必须加上strcut
对于上面使用typedef struct的代码,其实可以理解为
定义st_student结构体别名为t_student ,通常为了简化,直接使用别名即可。