最近在学数据结构,发现这个出现的频率有点高,奈何我悟性不高,好记性不如烂笔头,干脆记下来好了。
1.注意在c++和c里的区别
C语言:
1.1
struct Student
{
int a;
};
此时申请变量只能是struct Student s1
1.2
typedef struct Student
{
int a;
}Stu;
这里的typedef作用就是申请一个别名,我们可以声明变量时用Stu s1
也可以struct Student s1
1.3
还可以省略Student
typedef struct
{
int a;
}Stu;
此时声明变量时,只能用Stu s1
。
1.4
如果不加typedef,括号后依然写Stu时:
struct Student
{
int a;
}Stu;
此时的stu是一个Student结构类型的一个变量。
c++:
struct Student
{
int a;
};
声明变量时直接Student stu2;不用再写一个struct了。
别的和上述的C语言是一样的,就不写了。