定义结构体
1. 完整例子
| 1 | struct Point { |
| 2 | int x; |
| 3 | int y; |
| 4 | }; |
| 5 | |
| 6 | struct Student { |
| 7 | char name[16]; |
| 8 | int age; |
| 9 | float score; |
| 10 | }; |
2. 说明
- 成员可以是基本类型、数组、嵌套结构体
- 先定义类型,再声明变量
- 分号别忘:struct 定义结尾要 ;
| 1 | struct Point { |
| 2 | int x; |
| 3 | int y; |
| 4 | }; |
| 5 | |
| 6 | struct Student { |
| 7 | char name[16]; |
| 8 | int age; |
| 9 | float score; |
| 10 | }; |