title: Is it valid to access a multi dimensional C++ array as one contiguous block (on heap)
body: <p>Related thread here: <a href="https://stackoverflow.com/questions/2832970/does-c99-guarantee-that-arrays-are-contiguous">Does C99 guarantee that arrays are contiguous?</a></p>
  
  <p>Apparently <code>answer()</code> isn't valid below, but could be re-written to use char * or cast to int[nElements] (possibly).  I'll admit I don't understand the standard references and why a contiguous block of int couldn't be accessed via int* if properly aligned.  </p>
  
  <p>First is the following code block valid on most C++ platforms?</p>
  
  <pre><code>void answer(int *pData, size_t nElements)
  {
      for( size_t i=0; i&lt;nElements; ++i )
          pData[i] = 42;
  }
  
  void random_code()
  {
      int arr1[1][2][3][4];               // local allocation
      answer(arr1, sizeof(arr1) / sizeof(int));
      int arr2[20][15];
      answer(arr2, sizeof(arr2) / sizeof(int));
  }
  </code></pre>
  
  <p>Second does <code>answer()</code> remain valid for all allocation types (global, local, heap(hopefully correct!))?</p>
  
  <pre><code>int g_arr[20][15]; // global
  void foo() {
      int (*pData)[10] = new int[50][10];  // heap allocation, at least partially
      answer(&amp;pData[0][0], 50*10);
      // not even sure if delete[] will free pData correctly, but...
  }
  </code></pre>