#include <iostream>
using namespace std;
struct student {
char name[10];
int age;
int score;
} stu[3];
int main() {
// 补充代码,给结构体数组赋值
strcpy(stu[0].name, "Lin Dan");
stu[0].age = 28;
stu[0].score = 100;
strcpy(stu[1].name, "Feng Kun");
stu[1].age = 25;
stu[1].score = 92;
strcpy(stu[2].name, "Yang Qin");
stu[2].age = 27;
stu[2].score = 60;
// 输出结构体数组元素的成员项
for (int i = 0; i < 3; i++) {
cout << stu[i].name << "," << stu[i].age << "," << stu[i].score << endl;
}
return 0;
}
输出结果:
Lin Dan,28,100
Feng Kun,25,92
Yang Qin,27,60
内容由零声教学AI助手提供,问题来源于学员提问




