# 3D or 4D arrays

Printable View

• 02-25-2002
Unregistered
3D or 4D arrays
could someone explain to me the concept behind 3D or 4D arrays. how do i use them?
tnx
• 02-25-2002
Salem
char one_d[10];
char two_d[10][20];
char three_d[10][20][30];

Simple enough isn't it?

The first you would access by
one_d[x]

Then
two_d[x][y]

And
three_d[x][y][z];
• 02-25-2002
Shiro
Declaring higher-dimensional arrays goes almost the same way as declaring one dimensional arrays.

1D array of integers: int array [N];
2D array of integers: int array [N][M];
3D array of integers: int array [N][M][P];
4D array of integers: int array [N][M][P][Q];
etc.

To use them is also almost the same. For a 4D array you could do something like:

array [i][j][k][l] = value;

An higher order array can be seen as a matrix. A 3D array is a 3D matrix. Imagine a cube which is split up in little cubes. Then the little cube on array [1][2][3] is the cube which is on the first row, second colom and three deep. For a 4D structure and higher it is harder to understand the concept.
• 02-25-2002
ChrisE
think of arrays like this:

square paper, where you can write only one character in each square. a strip of square paper with 10 squares, but only 1 square thick would be a 1d array.

e.g

char Example[10];

now imagine you cut up the paper so that there were 10 rows of squares, and 10 columns. a 2d array,

e.g

char Example[10][10];

for a 3d array, imagine you had 10 bits of paper, each 10 squares by 10 squares in size, sort of like a card filing system a library has.

e.g

char Example[10][10][10];

4d array would be more complicated. imagine you had 10 card filing systems, each with 10 bits of paper, 10 rows and 10 columns, and imagine you had a filing cabinet, with 10 drawers, and you put a card filing system in each drawer.

e.g

char Example[10][10][10][10];

and i'm gettin slightly bored of typin now. hope that made sense.