# How does multidimensional array store variables

#### champ1

Jul 17, 2018
55
I've seen tutorials and youtube videos but I can't figure out how does multidimensional array stores variables

1 D array
When I write the below the line in code it means the compiler allocate five memory location and store five integer variable

Code:
int [5] = { 1, 2,3, 4,5};

2 D array
When I write the below the line in code it means the compiler allocate ten memory location

Code:
int [5] [2] ;

I don't understand 3 D array how does it store variables. How many variables are below the declaration store?

Code:
int [5] [2] [3];

#### Nanren888

Nov 8, 2015
623
youtube seems popular these days, Always liked text, myself.

Computer memory is just a sequence of locations.
All the work to notionally use it as rows, columns, is just the addressing, convention.
Most such systems are rectangular, so each row is by each column, by each next dimension.
Depending on the language and implementation, rows or columns first, but basically

I use Matlab mostly. in Matlab the first dimension is called "column" the second "row".

[5] means a column of 5 values.
[5,2] means do the same as above, twice, treat the first 5 as the first row, the next 5 as the second row. The second column of 5 is just offset and on the end of the first column.
[5,3] means do the same as above, three times, treat the first 5 as the first row, the next 5 as the second row, the next 5 as the third row
Moving to a row of columns is just an offset into the line of values, with the offset able to be calculated by the indices and the known length of each dimension.
[5,3,1] means do the same as above, three times, treat the first 5 as the first row, the next 5 as the second row, the next 5 as the third row
[5,3,2] means do the same as above, twice.That is [5,3] followed by [5,3]
.
[5,3] is like [5] [3]
[5,3,2] is like [5,3][2] or as in the language you are using [5][3][2] each dimensions replicates whatever is to the left of it.
So 3 by 2 columns of 5
or 2 blocks of { 3 rows of columns that are 5 long }
so
[5][2][3] is [5] replicated [2][3] which is [5] replicated [2] replicated [3]
Area of rectangular volume is l * b * h

#### roughshawd

Jul 13, 2020
286
Here is a little comic(cartoon rather) relief...

I am writing a program in my spare time called cybernecton database encryption... what it has is an array of data... 5 rows of 3 pieces of data each. In order for me to access any piece of data in the array(what I call the database) I have to identify the entire area of 15 as individual pieces singly. that means I have to access the entire 15 pieces with each item in it identified specifically... WHERE
any item, in col 3 can be used for any row, and any item in col 2 can be used for any row, but each row is unique and is maintained by the program. Now remember, arrays are nothing more than containers that hold the addresses.
I still have to build a 15x15 bank of memory to hold all the possibilities, even if there are only 225.... sound familiar??!!!
Why I decided to join the commercial wolrd dude... quit knocking yourself out! follow the rules... and keep an open mind!!!

Replies
10
Views
205
Replies
5
Views
403
Replies
5
Views
647
Replies
7
Views
457
Replies
4
Views
446