关于结构体数组指针的问题
mswag 2012-12-09 02:37:48 typedef struct{
char name[8];
int age;
} people;
int main(int argc, char** argv)
{
int i;
char temp[8];
people *p_map;
people aa;
memset(&aa,0, sizeof(aa));
strcpy(aa.name,"1234");
aa.age=8;
p_map=&aa;
printf("the len ==[%d]\n",sizeof(*p_map));
p_map=(people *)malloc(61);
memset(temp, 0x00, sizeof(temp)) ;
strcpy(temp,"test") ;
temp[4]='0';
for(i = 0;i<5;i++)
{
temp[4]+=1;
strncpy((p_map+i)->name,temp,5);
(p_map+i)->age=0+i;
printf("name==[%s],age==[%d]\n",(p_map+i)->name,(p_map+i)->age);
}
printf("the len ==[%d]\n",sizeof(*p_map));
以上一段的代码中前面明明定义的是结构体指针(people *p_map;),为什么后面可以使用结构体数组指针((p_map+i)->name),求解中......