首页 > 编程语言 > 详细

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

时间:2020-09-22 09:07:57      阅读:90      评论:0      收藏:0      [点我收藏+]
#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;
}

  

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

原文:https://www.cnblogs.com/nowroot/p/13710000.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!