title: How Physically are Arrays Stored (Specifically with dimensions greater than 2)?
body: <h2>What I Know</h2>
  
  <p>I know that arrays <code>int ary[]</code> can be expressed in the equivalent "pointer-to" format: <code>int* ary</code>. However, what I would like to know is that if these two are the same, how physically are arrays stored?</p>
  
  <p>I used to think that the elements are stored next to each other in the ram like so for the array <code>ary</code>:</p>
  
  <pre><code>int size = 5;
  int* ary = new int[size];
  for (int i = 0; i &lt; size; i++) { ary[i] = i; }
  </code></pre>
  
  <p>This (I believe) is stored in RAM like: <code>...[0][1][2][3][4]...</code></p>
  
  <p>This means we can subsequently replace <code>ary[i]</code> with <code>*(ary + i)</code> by just increment the pointers' location by the index.</p>
  
  <h2>The Issue</h2>
  
  <p>The issue comes in when I am to define a 2D array in the same way:</p>
  
  <pre><code>int width = 2, height = 2;
  Vector** array2D = new Vector*[height]
  for (int i = 0; i &lt; width; i++) {
      array2D[i] = new Vector[height];
      for (int j = 0; j &lt; height; j++) { array2D[i][j] = (i, j); }
  }
  </code></pre>
  
  <p>Given the class <code>Vector</code> is for me to store both x, and y in a single fundamental unit: (x, y).</p>
  
  <p>So how exactly would the above be stored?</p>
  
  <ol>
  <li><p>It cannot logically be stored like <code>...[(0, 0)][(1, 0)][(0, 1)][(1, 1)]...</code> as this would mean that the <code>(1, 0)</code>th element is the same as the <code>(0, 1)</code>th.</p></li>
  <li><p>It cannot also be stored in a 2d array like below, as the physical RAM is a single 1d array of 8 bit numbers:</p>
  
  <ul>
  <li><code>...[(0, 0)][(1, 0)]...</code></li>
  <li><code>...[(0, 1)][(1, 1)]...</code></li>
  </ul></li>
  <li><p>Neither can it be stored like <code>...[&amp;(0, 0)][&amp;(1, 0)][&amp;(0, 1)][&amp;(1, 1)]...</code>, given <code>&amp;(x, y)</code> is a pointer to the location of <code>(x, y)</code>. This would just mean each memory location would just point to another one, and the value could not be stored anywhere.</p></li>
  </ol>
  
  <p>Thank you in advanced.</p>