Tuesday, July 14, 2009

Example of multi dimensional array in turbo c?

i dont know how to manipulate array in turbo c

Example of multi dimensional array in turbo c?
An array is a variable that has space to hold 1 or more instances of only ONE data type.


unsigned int fuzz[256];

This allocates enough memory for 256 unsigned integers, referenced by the variable name fuzz.

You can store up to 256 unsigned integer numbers in that array. Example: 4,5,7,10,etc.

If you want to write a number to the array, you would write something like: fuzz[2]=4;

In this case, the unsigned integer 4 is written to the 3rd location of array fuzz (array numbers start at 0, not 1!).

A multi-dimensional array is like a matrice.

Using my previous example, you can think of a single array as 1 row of numbers. A multi-dimensional array can be thought as having multiple rows of data.


unsigned int foo[256][256];

This is a two dimensional array.

Think of it as 1 row of numbers, with another row of numbers beneath it.

To write to the first location in the SECOND row, you could do this: foo[1,0]=4.

The first number in the bracket represents the row number (0-1 in this case) and the second number represents the location on that particular row. The number 4 is written to the second row, 1st column on that row.

No comments:

Post a Comment