参考:http://blog.youkuaiyun.com/itguangit/article/details/50117295
C中:struct Student才相当于一个数据类型
struct Student
{
int a;
}Stu;
struct Student是结构体类型Stu是变量,等价于struct Student Stu;
typedef struct Student
{
int a;
}Stu;
Stu和struct Student都是结构类型(有Stu作别名时Student可省略)
声明变量时可以:Stu stu;或者struct Student stu;
C++中:Student相当于一个数据类型
struct Student
{
int a;
}Stu;
struct是结构体类型标识符
Student是结构体类型
Stu是变量,等价于Student Stu等价于struct Student Stu;
typedef struct Student
{
int a;
}Stu;
Stu和Student都是结构体类型
声明变量时可以:Stu stu;或者Student stu;或者struct Student stu;
其他:
1.在C中,struct不能包含函数。在C++中,对struct进行了扩展,可以包含函数。
2.在C/C++中,struct ...{}Stu; Stu是变量,typedef struct ...{}Stu; Stu是结构体类型。

本文详细介绍了在C和C++中struct的使用方法及其区别。解释了struct如何定义和声明变量,并通过示例说明了typedef的作用。此外,还对比了C与C++中struct的不同之处。
6365

被折叠的 条评论
为什么被折叠?



