关注微信公众号“二进制小站”~~获取更多分析~~(文末二维码~~)
1------------------------------------------------------------------------------
1.1c中
在c中定义一个结构体类型,要用typedef
如:typedef struct Student
{
int age;
}Stu;
这种定义形式,在变量声明时,可用:Stu student1;
如果没有typedef的话,变量声明应该为struct Student student1;
这里Stu 相当于struct Student 的别名。Stu==struct Student。
另外,也可以不写Student,直接用typedef struct定义:
如:typedef struct
{
int age;
}Stu;
此时,函数声明只能是:Stu student1。
1.2c++中
在c++中,定义结构体比较简单,如下。
struct Student
{
int age;
};
变量声明时,为:Student student1.
2.----------------------------------------------
在C++中也可以通过typedef定义结构体,但会造成一下区别:
struct Student
{
int age;
}Stu;
此时Stu表示结构体声明的一个变量;
typedef struct Student
{
int age;
}Stu;
此时,Stu与C语言下的含义相同,表示struct Student,可以用Stu student声明变量。
文章参考:http://www.cnblogs.com/qyaizs/articles/2039101.html