c 与c++中结构体struct
2018-02-25 23:57
197 查看
1.C语言中定义:
typedef struct Student {int a;
}Stu;
或者:
typedef struct {
int a;
}Stu;
其中Student称为标签,可与struct一起组成类型名,即struct Student 等价于类型名,也与 Stu 等价。
2.C++中的定义:
struct Student1 {
int a;
}stu1;
或:struct Student1 { int a; };
或者:
typedef struct Student2 {
int a;
}stu2;
其中 Student1 为类型名, stu1为变量名,但stu2为类型名。即有:
stu1.a;
stu2 s2; s2.a;
(1) typedef struct Student2 stu3; 这行代码是指typedef重新给 struct Student2 起个别名叫stu3.
总结就是在定义这类变量时:
C语言:
(1) struct Student s;
(2) Stu s;
C++:
(1)struct Student1 s;
(2) stu2 s;
(3) Student1 s;
相关文章推荐
- C++学习笔记二十二 - 简单的结构体struct
- C/C++中的结构体(struct)
- C语言和C++中结构体struct区别
- struct结构体在c和c++中的差别
- 从C到C++——结构体(struct)的涅槃
- C/C++ struct 结构体定义 用法详解
- C++中结构体与类的区别(struct与class的区别)
- c/c++中使用sizeof计算结构体struct和类class的长度(字节)
- C++学习总结(五)——结构体(struct),联合体(union)
- 从C到C++——结构体(struct)的涅槃
- 关于C/C++中结构体(Struct)类型的sizeof结果的探讨
- C++中结构体与类的区别(struct与class的区别)
- 《算法笔记》2.8小节——C/C++快速入门->结构体(struct)的使用
- 《算法笔记》2.8小节——C/C++快速入门->结构体(struct)的使用
- C++中结构体与类的区别(struct与class的区别)
- c++中关于类(class)和结构体(struct)的区别个人总结
- C++中的结构体struct
- 深入剖析C++中的struct结构体字节对齐
- C/C++中结构体(struct)知识点强化(一)
- C++中结构体与类的区别(struct与class的区别)