# Thread: How does multidimensional array store variables

1. ## How does multidimensional array store variables

I am having trouble to understand How does multidimensional array store variables

No problem with 1D array
Code:
` int one_dim[] = { 1,2,3 };`
My understanding for 2D
Code:
``` #define row    3
#define coulmn  4

int two_dim[row][coulmn] = { {0,1,2,3}, {4,5,6,7}, {8,9,10,11} };```
I am having trouble to understand N D array

Code:
` int N_dim;`
any idea how to remember 2. The right-most dimension varies quickest.

Or you need as many initial opening braces as you've got dimensions.
Code:
```int one_dim = { 1,2,3,4 };
int two_dim = {
{ 1,2,3,4 },
{ 1,2,3,4 },
{ 1,2,3,4 },
};
int three_dim = {
{
{ 1,2,3,4 },
{ 1,2,3,4 },
{ 1,2,3,4 },
},
{
{ 1,2,3,4 },
{ 1,2,3,4 },
{ 1,2,3,4 },
},
}``` 3. It might help if you really, really learn how C declarations work.

Consider this:
Code:
`    int ary;`
In C, the rule is that type operators (pointer, array, function) are read postfix, then prefix, starting with the declarator (if there is one). The C operator precedence supports this.

This means, in our example, that we read it like:

1. ary is an
2. array-of-3
3. array-of-5
4. int

The important thing is that because the declaration and evaluation of identifiers uses the same structure, when you understand how to read and write them, you understand how to look at partial pieces of them. Consider this:

Code:
`    a`
What's the type of a? Well, you can replace it in the declaration, and then read it in the same old way: postfix, then prefix, then type specifiers:

1. Ay_sub_won is an
2. array of 5
3. int

Why does this matter? Because "objects" in C represent a single block of memory! Meaning that a is an "object" that occupies a block of memory that is stored immediately after a and immediately before a. Furthermore, you know that a is stored right before a. With this information alone, you should be able to build a "map" of where the objects are in memory.

To boil it down, a 2-d array is like a column of text: the dimension closest to the variable name (a) selects the "row" to read, and then the dimension farther away selects the item within the row (the "column"). This is known as "row-major order" (as opposed to "column-major" order).

Similarly a 3-d array is like a stack of papers. The first dimension selects the page, the second dimension selects the row of text, the third dimension selects the character within the row. 4. Originally Posted by Salem The right-most dimension varies quickest.

Or you need as many initial opening braces as you've got dimensions.
I understand following declarations
Code:
```int one_dim ; // It can store 4 variables
int two_dim ; // It can store 16 variables
int three_dim ;// it can store 24 variables```
How many variable can store following declarations ?

Code:
` int three_dim` 5. You just multiply all the dimensions
Code:
```int one_dim ; // It can store 4 variables = 4
int two_dim ; // It can store 16 variables = 4 * 4
int three_dim ;// it can store 24 variables = 2 * 3 * 4``` Popular pages Recent additions array, int, store, trouble, understand 