Multidimensional array with unequal second dimension size using malloc()
Posted
by user288422
on Stack Overflow
See other posts from Stack Overflow
or by user288422
Published on 2010-03-08T00:14:32Z
Indexed on
2010/03/08
0:17 UTC
Read the original article
Hit count: 596
Hello,
I am playing around with multidimensional array of unequal second dimension size. Lets assume that I need the following data structure:
[&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;
}
I did some tests and it seems like I can store a value at a[1][3]. Does it mean that rows in my array are of equal size 10?
© Stack Overflow or respective owner