参考来源:

作者:smile刺客
链接:https://www.jianshu.com/p/f0c3d3f78aa1
来源:简书

1 首先:

在C中定义一个结构体类型要用typedef:

typedef struct Student

{

int a;

}Stu;(别名)

在声明变量的时候:Stu stu1;

如果没有typedef声明变量的时候:struct Student stu1;

另外这里也可以不写Student(于是也不能struct Student stu1;了)

typedef struct

{

int a;

}Stu;

但在c++里很简单,直接

struct Student

{

int a;

};

于是就定义了结构体类型Student,声明变量时直接Student stu2;

===========================================

2其次:

在c++中如果用typedef的话,又会造成区别:

struct Student

{

int a;

}stu1;//stu1是一个变量

typedef struct Student2

{

int a;

}stu2;//stu2是一个结构体类型

使用时可以直接访问stu1.a

但是stu2则必须先 stu2 s2;

然后 s2.a=10;




posted on 2019-09-11 19:30  凭栏听雨客  阅读(281)  评论(0编辑  收藏  举报