关于单片机为啥要把结构体用typedef重定义--为已经存在的变量类型重新命一个别名
struct student
{
int score;
char *name;
};
因为在C语言中结构体在函数中定义变量的时候需要这样写: struct student stu1;
定义变量需要每次吧struct加上,这样比较麻烦。c++里边的话可以不加struct直接用student来定义变量。
所以用typedef可以解决这个麻烦,如下。
typedef struct student //student 可以省略
{
int score;
char *name;
}STU; //这样就把struct student用STU来替换了,避免每次定义变量都要写struct的麻烦。