【发布时间】:2010-03-08 00:14:32
【问题描述】:
我正在玩不等第二维大小的多维数组。 假设我需要以下数据结构:
[&ptr0]->[0][1][2][3][4][5][6][7][8][9]
[&ptr1]->[0][1][2]
[&ptr2]->[0][1][2][3][4]
int main()
{
int *a[3];
int *b;
int i;
a[0] = (int *)malloc(10 * sizeof(int));
a[1] = (int *)malloc(2 * sizeof(int));
a[2] = (int *)malloc(4 * sizeof(int));
for(i=0; i<10; i++) a[0][i]=i;
for(i=0; i<2; i++) a[1][i]=i;
for(i=0; i<4; i++) a[2][i]=i;
}
我做了一些测试,似乎我可以在 a[1][3] 中存储一个值。这是否意味着我的数组中的行大小相同 10?
【问题讨论】:
标签: c multidimensional-array malloc