Single and Multi-dimensional Arrays

Let us first look at how we define arrays in C:

int listofnumbers[50]; or, more general: type array_name[arraysize]

With this statement we simply told the program that listofnumbers is a 1-dimensional array, containing 50 elements of type int. These elements are listofnumbers[0], ..., listofnumbers[49] .

BEWARE: Indexes in C start at 0 and therefore end one less the array size ! If you are used to another computing language, this might require some practice to get used to.

Elements can be accessed in the following ways:

thirdnumber=list0fnumbers[2];

list0fnumbers[5]=100;

Multi-dimensional arrays can be defined as follows:

int tableofnumbers[50][50]; (for two dimensions).

For further dimensions simply add more [ ] containing the particular dimensions:

int bigD[50][50][40][30].....[50];

Elements of multi-dimensional arrays can be accessed in the following ways:

anumber=tableofnumbers[2][3];

tableofnumbers[25][16][37]=100;


drago@scri.fsu.edu
Jan. 1997