@CrazyHenry
2018-01-23T05:13:37.000000Z
字数 676
阅读 1326
ccccC++Primer
- Author:李英民 | Henry
- E-mail: li
_yingmin@outlookdotcom- Home: https://liyingmin.wixsite.com/henry
快速了解我: About Me
转载请保留上述引用内容,谢谢配合!
在C中定义一个结构体类型要用typedef:
typedef struct Student{int a;}Stu;
于是在声明变量的时候就可:Stu stu1;(如果没有typedef就必须用struct Student stu1;来声明)
这里的Stu实际上就是struct Student的别名。Stu==struct Student
另外这里也可以不写Student(于是也不能struct Student stu1;了,必须是Stu stu1;)
typedef struct{int a;}Stu;
但在c++里很简单,直接
struct Student{int a;};
于是就定义了结构体类型Student,声明变量时直接Student stu2;
在c++中也可用typedef
struct Student{int a;}stu1;//stu1是一个变量
typedef struct Student2{int a;}stu2;//stu2是一个结构体类型=struct Student2
使用时可以直接访问stu1.a
但是stu2则必须先 stu2 s2;
然后 s2.a=10;
