3D array question

How are values visually stored in a 3D array?
If I have a int a[3][3][2] = {1, 2, 3 ... 18}

FRONT:
1 2 3
4 5 6
7 8 9

BACK:
10 11 12
13 14 15
16 17 18

or will it be stored like this

FRONT:
1 3 5
7 9 11
13 15 17

BACK:
2 4 6
8 10 12
14 16 18
c++ is row major, and everything is stored in 1 dimension.

a 1d array is just as it seems, in memory one after another.

a 2d array is an array of 1d arrays, rows first, so its r1c1 r1c2 r1c3 ... r2c1 r2c2

a 3d array follows this pattern. lets call the 3rd dimension z I guess.
r1c1z1 r1c1z2 ... r1c2z1 r1c2z2 ... r2c1z1 ... and so on.

Nothing is stored visually, computer's cant see. I am not trying to be a jerk, but front and back and top and bottom and left and right and all that are all human constructs applied to the data. Depending on where YOU as the programmer visualize 0,0,0 to be, that determines the orientation of your 3-d space and everything falls into place from there. But you can pick any of the corners for 0,0,0 and then you can choose which dimension is 2nd and 3rd from there. Its.. user defined.


Topic archived. No new replies allowed.