首先请看示例:注意蓝色部分
#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维。
加载中,请稍候......