# Thread: Multidementional arrays, need concept explanation??

1. ## Multidementional arrays, need concept explanation??

Hi everyone,
today, My C prof covered multidimensional arrays...he says that, there exist, in addition to the two dimensional arrays, n-dimensional arrays.. he asks us not to pay attention to these concepts and focus only on the two dimensional model..
The problem is that i want to go deeper in C, deeper than the school program, and i guess it's crucial to understand what means to have more than two dimensional array..
PS: i can imagine what is gonna be like a three-dimensional array in reality...but how that works in memory??

2. You can have as many dimensions as you like [1]:

Code:
```int onedim[10];
int twodim[10][10];
int threedim[10][10][10];
int fourdim[10][10][10][10];
int fivedim[10][10][10][10][10];```
I'll leave it to you to figure out what sixdim and tendim would look like.

And tendim might struggle to fit in a 32-bit machine - care to guess why?

[1] I don't know if the C standard has a specific limit for what the compiler must cope with - if there is such a limit, it's still allowed for the compiler to allow more dimensions, if it likes to.

Edit: I missed your last question. The compiler will translate ANY multidimensional array into a block of memory that is the right size to cope with the data. How that's organized is up to the compiler, but generally it's just like a one dimensional array with index calculation like this:
n0 + n1 * n0_max + n2 * (n0_max * n1_max) ...

--
Mats

3. Ok, so you wanna say that the compiler breaks everything down to only two dimensions..??

4. the compiler breaks all multidimensional arrays to one dimension, not two. So it's just a bunch of array elements in a row, and it calculates the position you want.

5. very interesting, I to was wondering this some time back. It's good to have an insight.

n0 + n1 * n0_max + n2 * (n0_max * n1_max) ...