1 2 3 4

Multi-Dimensional Arrays

* *

A multi-dimensional array is just an array of arrays We declare a 2 dimensional array with:

int a[10][20];

This can be viewed as 10 arrays, each of which contain 20 integer elements
An individual element of this array is retrieved with:

int x;
x = a[i][j];

Naturally we can still do things like the following

int* pa;

*

*

*

IMAGE imgs/lec-06.sli01.gif

/* or evenpa = a; */

j

IMAGE imgs/lec-06.sli02.gif

a[0][19] a[1][19]

a[9][19]

pa

x = *(pa+i*20+j);

/* x = a[i][j];

*/

January 21, 1999

Page 1

copyright UoA