[A89] Multi-dimensional Arrays in C...
[Prev][Next][Index][Thread]
[A89] Multi-dimensional Arrays in C...
I'm not sure if this would even be useful, but is it possible to create
dynamic multi-dimensional arrays that can use array notation?
For instance: I know you can do this:
int array[3][4];
array[0][2] = 4;
printf("%d",array[0][2]);
and you can do this:
**array+3 = 4;
printf("%d",**array+3);
Both will give you 4, but how can you declare array[3][4] as **array or
*array and allocate it dynamically?
I've tried things like this:
int **array;
array = (int [][])calloc(3,4*sizeof(int));
and
array = (int **)calloc(3,4*sizeof(int));
and even
array = (int [3][4])calloc(3,4*sizeof(int));
The first and 3rd give me compiler errors, the second one segfaults. (This
is not necessarily TI specific -- I tried this with gcc for Sparc).
Any suggestions?
Thanks in advance,
John David Ratliff
jdratlif@cs.indiana.edu
Follow-Ups: