结构体前面加typedef

发布时间 2023-11-23 09:49:12作者: 最爱丁珰

如果是C语言,那么在定义了一个结构体之后,在声明这个结构体变量的时候必须要在类型前加上struct

比如


struct Student{         //声明结构体
    char name[20];      //姓名
    int num;            //学号
    float score;        //成绩
};
struct Student stu1;

如果是C++最后一排就可以写成Student stu1;

如果在定义结构体时,struct前面加上typedef,比如

typedef struct
{
  int n;
  char ch[8];   
}per;

此时per不是结构体变量名,而是结构体类型

比如声明一个结构体时:per a