区别:
1 首先://注意在C和C++里不同
①C定义结构体类型最好用typedef:
typedef struct Student
{
int a;
}Stu;
声明变量:Stu stu1; 如果没有typedef就必须用struct Student stu1;Stu==struct Student
也可以不写Student
typedef struct
{
int a;
}Stu;
声明变量:必须是Stu stu1;
②c++里很简单,定义直接
struct Student
{
int a;
};
声明变量:直接Student stu1;
======================================================================================
2.访问变量:
c++中如果用typedef的话,要注意区别:
struct Student
{
int a;
}stu1;//stu1是一个变量
使用时可以直接访问stu1.a
typedef struct Student2
{
int a;
}stu2;//stu2是一个结构体类型=struct Student2
stu2则必须先 stu2 s2;
然后 s2.a=10;
======================================================================================
3 定义多个变量
如果在c程序中我们写:
typedef struct
{
int num;
int age;
}aaa,bbb,ccc;
这算什么呢?这相当于
typedef struct
{
int num;
int age;
}aaa;
typedef aaa bbb;
typedef aaa ccc;
也就是说aaa,bbb,ccc三者都是结构体类型。声明变量时用任何一个都可以
参考:http://www.cnblogs.com/qyaizs/articles/2039101.html