解题思路:用指向结构体数组的指针来解决。
#include<stdio.h>
struct Student{
int num;
char name[20];
char sex;
int age;
};
int main(){
struct Student stu[3] = {{10101,"li",'m',18},{10102,"liu",'f',20},{10103,"wang",'m',90}};
struct Student *p;
printf("NO. ,NAME ,SEX ,AGE ");
printf("\n");
for(p = stu;p<stu+3;p++){
printf(" %5d %-6s %2c %4d\n",p->num,p->name,p->sex,p->age);
}
return 0;
}
该程序定义了一个包含编号(num)、姓名(name)、性别(sex)和年龄(age)的结构体Student,并创建了一个包含三个元素的结构体数组。然后,通过指针p遍历数组,打印每个学生的详细信息。
266

被折叠的 条评论
为什么被折叠?



