struct 就是结构体。
typedef 是别名。
typedef struct 就是给struct 类型起别名。但这不是使用的方便之处。
struct Student{
int a;
}Stu1;
Stu1 是一个结构体的变量。在新建其它的struct Student 时,必须使用 struct Student 为类型名后面追加变量名。此时typedef的作用就来了。
typedef struct Student{
int a;
}Stu1;
此时的Stu1 不是变量了,而是类型,是struct Student的别名。在新建struct Student 变量的时候就可以直接使用 Stu1 作为类型名。
struct Student{
int a;
}Stu1;
如果只有一个Stu1在最后,等于说只定义了一个结构体变量 Stu1,加上typedef 等于说给结构体 stuct Student 设置别名 Stu1,此时Stu1是一个别名,而不是一个变量
Over!