首页 > 编程语言 > 详细

C语言结构体数组

时间:2014-01-23 19:07:41      阅读:355      评论:0      收藏:0      [点我收藏+]
bubuko.com,布布扣
#include <stdio.h>

int main()
{
    /***************************************************
     *结构体数组:数组的每个元素都是结构体类型,注意是同一种结构体类型
     *
     *    struct RankRecord
     *    {
     *       int no;
     *       int score;
     *       char *name;
     *    };
     *    struct RankRecord record[3];
     ****************************************************/

    struct RankRecord
    {
         int no;
         int score;
         char *name;
    };
    struct RankRecord record[3] =
    {
            {1, 90, "zhangsan"},
            {2, 80, "lisi"},
            {3, 100, "wangwu"}
    };
    for (int i=0; i<3; i++)
    {
        printf("record[%d].no = %d, record[%d].score = %d, record[%d].name = %s \n",
                i, record[i].no, i, record[i].score, i, record[i].name);
    }
     return 0;
}
bubuko.com,布布扣
record[0].no = 1, record[0].score = 90, record[0].name = zhangsan 
record[1].no = 2, record[1].score = 80, record[1].name = lisi 
record[2].no = 3, record[2].score = 100, record[2].name = wangwu 

C语言结构体数组

原文:http://www.cnblogs.com/heml/p/3530928.html

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