Multi Dimensional Arrays in C of variable size - (The traditional way)
Hi to all!
I am curious if there is a way to describe and use variable sized multi-dimensional arrays in C using pointers...
I mean, for 1-dimensional array e.g. I can use the following piece of code:
...
int i , N;
int *array;
scanf("%d", &N);
array = (int*) malloc(N*sizeof(int));
for (i=0; i<N; ++i) array[i] = i; // Assigning values to the array
for (i=0; i<N; ++i) printf("%d ", array[i]); // Printing the assigned values
free (array);
...
But what about the two dimensional array[N][M] ?
I guess i have to use a double pointer e.g: int **array. But how exactly?
Note that I use C90 and not C99.
Thanks in advance
Vas ...
|