#include<iostream>
using namespace std;
//1.创建学生数据类型:学生包括(姓名,年龄,分数)
#include<string>
struct Student{
string name;
int age;
int score;
}s3;
int main(){
struct Student stuArray[3]={
{"张三",18,100},{"李四",28,99},{"王五",38,66}
};
//3、给结构体数组中的元素赋值
stuArray[2].name="老六";
stuArray[2].age=18;
stuArray[2].score=100;
for(int i=0;i<3;i++){
cout<<stuArray[i].name<<stuArray[i].age<<stuArray[i].score;
}
system("pause");
return 0;
}
#include<iostream>
using namespace std;
#include<string>
struct Student{
string name;
int age;
int score;
}s3;
int main(){
//1、创建学生结构体变量
struct Student s={"张三",18,100};
//2、 通过指针指向结构体变量
struct Student *p=&s;//(struct可以省略)
// 3、 通过指针访问结构体变量中的数据
cout<<"姓名: "<<p->name<<"年龄: "<<p->age<<"分数: "<<p->score<<endl;
system("pause");
return 0;
}