struct与typedef struct的区别

C语言中因为在声明结构体时struct不能省略

struct Student{//定义结构体
int age;
int grade;
}
struct Student s1;

此时可以在定义结构体时加上typedef

typedf struct Student{//定义结构体
int age;
int grade;
}stu;
stu s1=NULL;

此时加上typedf,stu就相当于struct Student
所以stu s1就相当于 struct Student s1;


C++中声明结构体时typedf可以省略

struct Student{//定义结构体
int age;
int grade;
}
Student s1;//声明结构体

也可以用这种形式

struct Student{//定义结构体
int age;
int grade;
}s1;

此时s1相当于
struct Student s1;

发布了83 篇原创文章 · 获赞 44 · 访问量 6966

猜你喜欢

转载自blog.csdn.net/qq_44620773/article/details/104540998