加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

结构数组,结构数组类型(typedef)

(2012-04-01 16:04:48)
标签:

it

分类: 零碎笔记
首先请看示例:注意蓝色部分
#include <stdio.h>
#include <stdlib.h>

int main(void)
{
    typedef struct ArcCell{
        int age;
        float length;
    }AcrCell, AdjMatrix[2][3];

    struct student{
        int age;
        float length;
    }MG[2][3];

    int i,j;
    AdjMatrix     t_arcs;
    for(i=0;i<2;i++)
        for(j=0;j<3;j++)
            scanf("%d %f",&t_arcs[i][j].age,&t_arcs[i][j].length);//注意此处语法
    
    for(i=0;i<2;i++)
        for(j=0;j<3;j++)
            printf("age=%d, length %f\n",t_arcs[i][j].age,t_arcs[i][j].length);//注意此处语法    

    for(i=0;i<2;i++)
        for(j=0;j<3;j++)
            scanf("%d %f",&MG[i][j].age,&MG[i][j].length);

    for(i=0;i<2;i++)
        for(j=0;j<3;j++)
            printf("age=%d, length %f\n",MG[i][j].age,MG[i][j].length);    

    system("PAUSE");
    return 0;

说明:
1、结构类型
typedef struct ArcCell{
    int age;
    float length;
}AcrCell;
AceCell acrs;
tips:
    AcrCell是一个类型名,该类型表示结构struct ArcCell;所以arcs就是一个struct ArcCell类型的变量。

2、结构数组类型
typedef struct ArcCell{
    int age;
    float length;
}AcrCell, AdjMatrix[2][3];
AdjMatrix t_arcs;
tips:
    其中AdjMatrix是一个类型的名称,该类型是一个以结构AcrCell为元素的2*3维数组,t_arcs是该类型的变量。上述声明与下面等同:
typedef struct ArcCell{
    int age;
    float length;
}AcrCell;
typedef AcrCell AdjMatrix[2][3];
AdjMatrix t_arcs;
    使用t_arcs元素时直接用数组方式调用,具体参看程序里面。

3、结构数组
struct student{
    int age;
    float length;
}MG[2][3];
tips:
    MG不是类型名称,而是一个数组名称,该数组元素是struct student,2*3维。

0

阅读 收藏 喜欢 打印举报/Report
前一篇:堆、栈、队列
后一篇:欧拉回路
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有