10.c
#include<stdio.h>
struct student
{
int num;
char *name;
char *sex;
}stu1;
struct student stu[3]=
{{1,"student1","female1"},{2,"student2","female2"},{3,"student3","female3"}};
int main()
{
struct student *p;
struct student *pp;
int i=0;
for(p=stu;p<stu+3;p++,i++)
{
printf("num:%d\n",p->num);
printf("name:%s\n",p->name);
printf("sex:%s\n",p->sex);
}
printf("\\\\\\\\\\\\\\\\\\\\\\change\\\\\\\\\\\\\n");
pp=&stu[1].name;
//the same as pp=(struct student*)&stu[1].name;
//pp start from name filed of stu[1],not num
printf("name:%s\n",pp->name);//print name field--------but have printed sex field
//pp->name -----is translated to----the first element of pp--------by compiler
(++pp)->name="shit";//change the sex--------but have changed the sex field
printf("\\\\\\\\\\\\\\\\\\\\\\changed\\\\\\\\\\\\\n");
for(p=stu;p<stu+3;p++,i++)
{
printf("num:%d\n",p->num);
printf("name:%s\n",p->name);
printf("sex:%s\n",p->sex);
}
}