结构体的定义和使用(1)

结构体概念:

自定义数据类型,一些类型的集合组成一个类型。

结构体的定义和使用:

struct 结构体名 {成员1成员2,...};

结构体创建变量的三种方式:

1.struct 结构体名 变量名;(推荐)

1     struct Student s1;
2     s1.name = "张三";
3     s1.age = 18;
4     s1.score = 100;    

2.struct 结构体名 变量名 ={成员1成员2...};(推荐)

1 struct Student s1 = { "李四",18,100 };

3.定义结构体时顺便创建变量(不推荐)

1 struct Student
2 {
3     string name;
4     int age;
5     int score;
6 }s3;

猜你喜欢

转载自www.cnblogs.com/huanian/p/12687983.html
今日推荐