title: C / C++ MultiDimensional Array Internals
body: <p>I have a question about how C / C++ internally stores multidimensional arrays declared using the notation <code>foo[m][n]</code>.  I am not questioning pure pointers to pointers etc...  I am asking because of speed reasons...</p>
  
  <p>Correct me if I am wrong, but syntactically <code>foo</code> is an array of pointers, which themselves point to an array</p>
  
  <pre><code>int foo[5][4]
  *(foo + i)           // returns a memory address
  *( *(foo + i) + j)    // returns an int
  </code></pre>
  
  <p>I have heard from many places that the C/C++ compiler converts <code>foo[m][n]</code> to a one dimensional array behind the scenes (calculating the required one dimension index with <code>i * width + j</code>).  However if this was true then the following would hold</p>
  
  <pre><code>*(foo + 1)          // should return element foo[0][1]
  </code></pre>
  
  <p>Thus my question:
  Is it true that <code>foo[m][n]</code> is (always?) stored in memory as a flat one dimensional array??  If so, why does the above code work as shown.</p>