嵌入式-C语言基础:通过结构体指针访问结构体数组
阅读原文时间:2023年07月09日阅读:1

#include
#include
struct Student
{
char name[32];
int age;
int height;
int weight;
};

int main()
{

struct Student Stus\[3\]={  
    {"hhh",12,45,45},  
    {"ttt",16,24,45},  
    {"kkk",18,23,45},  
};  
printf("\\n\\n\\n");  
struct Student \* stusP=Stus;  
//通过结构体指针遍历结构体数组  
int size=sizeof(Stus)/sizeof(Stus\[0\]);  
for(int i=0;i<size;i++)  
{  
    printf("地址=%p,name=%s\\n",stusP,stusP->name);  
    stusP++;  
}  
return 0;  

}

输出结果:

地址=000000000061FD40,name=hhh
地址=000000000061FD6C,name=ttt
地址=000000000061FD98,name=kkk