用户自定义的数据类型,允许用户存储不同的数据类型(一些数据集合组成一个类型)
语法:struct 结构体名 {结构体成员列表};
通过结构体创建的变量的方式有三种:
struct 结构体名 变量名
struct student{
string name;
int age;
int score;
}
int main()
{
struct student s1;
s1.name="小王";
s1.age="80";
s1.score="60";
system("pause");
return 0;
}
struct 结构体名 变量名
struct student{
string name;
int age;
int score;
}
int main()
{
struct student s2={"小王",80,60};
system("pause");
return 0;
}
定义结构体时顺便创建变量
struct student{
string name;
int age;
int score;
}s3;
int main()
{
s3.name="小王";
s3.age="80";
s3.score="60";
system("pause");
return 0;
}