数组和结构体数组和结构体指针使用数组

#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <time.h>
#include <pthread.h>
#include <semaphore.h>
#include <unistd.h>
#include <signal.h>
#include <string.h>
#include <stdlib.h>

// 一个苹果  二个苹果  3个苹果
struct _fruit
{
    char name[125];
    int  size;
    int  color;
    char*  region;
    int  price;
};
typedef struct _fruit  fruit_t;


static fruit_t applet[100] =
{
   {
       .size = 100,
       .region = "shenzhen",
       .price = 5,
   },

  {
        .size = 100,
        .region = "guangzhan",
        .price = 10,
   },

   {
        .size = 100,
        .region = "guangzhan",
        .price = 2,
   },

   {
        .size = 100,
        .region = "guangzhan",
        .price = 4,
   },

  {
        .size = 100,
        .region = "guangzhan",
        .price = 10,
   },
};

int main()
{
    fruit_t*p  = applet;  // 结构体指针访问结构体数组
    printf("size is %d\n",p[0].size);
    printf("color is %d\n",p[0].color);
    printf("price is %d\n",p[4].price);
    for(;;);
    return 0;
}

  

posted @ 2020-09-22 07:39  卷哭你  阅读(338)  评论(0编辑  收藏  举报