嵌入式-C语言基础:通过结构体指针访问结构体数组

#include<stdio.h>
#include<string.h>
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

posted @ 2022-11-03 22:32  WellMandala  阅读(157)  评论(0)    收藏  举报