(1)结构数组的初始化:struct Stu{
int age;
char *name;
};
1)定义结构体数组同时初始化
struct Student{
char name[20];
int age;
}boy[3]={{"sb",18},{"zbz",38},{"cgx",28}};
2)定义同时进行初始化
struct Student girls[2]={{"feng",18},{"cjc",28}};
3)定义后初始化,整体赋值
struct Student ds[2];
ds[0]=(struct Student){"ttttt",18};
ds[1]=(struct Student){"ffff",18};
4)先定义结构体数组,后初始化
struct Student stu[2];
scanf("%s",stu[0].name);/strcpy(stu[0].name,"aaaaa");
stu[0].age = 19;
(2)结构体数组遍历
for (int i = 0; i<3;i++){
printf("name:%s,age:%d\n",boy[i].name,b);
oy[i].age } |
|