例11.4指向结构体数组的指针的应用。
struct student
{int num;
char name[20];
char sex;
int age;
};
struct student stu[3]={{10101,"Li Lin",'M',18},{10102,"Zhang Fun",'M',19},{10104,"Wang Min",'F',20}};
main()
{struct student*p;
printf(" No.Namesexage\n");
for (p=stu;p<stu+3;p++)
printf("%5d %-20s %2c %4d\n",p->num,p->name,p->sex,p->age);
}
运行结果如下:
No. Name sex age
10101 Li Lin M 18
10102 Zhang Fun M 19
10104 wang Min F 20
struct student
{int num;
char name[20];
char sex;
int age;
};
struct student stu[3]={{10101,"Li Lin",'M',18},{10102,"Zhang Fun",'M',19},{10104,"Wang Min",'F',20}};
main()
{struct student*p;
printf(" No.Namesexage\n");
for (p=stu;p<stu+3;p++)
printf("%5d %-20s %2c %4d\n",p->num,p->name,p->sex,p->age);
}
运行结果如下:
No. Name sex age
10101 Li Lin M 18
10102 Zhang Fun M 19
10104 wang Min F 20