You already know what a multidimensional array is and why it is useful for holding lots of data. Now let's open the hood and see how the computer actually keeps these arrays in memory.
Think of your computer's memory (RAM) as one very long shelf. The shelf is split into many small blocks, placed one after another in a single straight line.
0, 1, 2, 3, and so on.The key idea: memory is one-dimensional. It is just a flat, linear sequence of numbered blocks. There are no rows and columns inside the actual hardware — only a single line.
A multidimensional array has *shape*. A 2D array looks like a grid with rows and columns. A 3D array looks like a stack of grids. In your head and in your code, the data lives in this nice grid form.
But memory is just one straight line. So a grid cannot be stored directly. We need a trick.
> The solution: take the N-dimensional array and map it onto a one-dimensional line of blocks. We flatten the grid into a single row, place every value into the linear memory one after another, and remember a rule for where each value goes.
So a 2D array like {value1, value2, value3, ...} gets laid out in memory as a plain sequence: value1, value2, value3, ... in consecutive blocks.
There are really two views of the same data:
numbers[i][j]. The two numbers i and j are the coordinates of the element.Because of this gap, the computer needs a fast and efficient formula that converts the N indices you typed (like i and j) into the single memory address where that value is really stored. This conversion happens constantly, so it must be quick.
You may hear these two terms:
Mapping a grid into a flat memory line is the same kind of idea: change the form for storage, then be able to recover the original.
When we flatten a grid into a line, we must decide the *order* in which the elements go in. There are two common techniques:
Different programming languages pick different orders. In the upcoming lessons, we will study both orderings in detail and see which languages use each one.
The main takeaway: memory is a single straight line of addressed blocks, multidimensional arrays must be flattened to fit into it, and a simple formula maps your N indices to one address — using either row major or column major order.