title: Multidimensional arrays allocated through calloc
body: <p>I have a question about how memory is allocated when I <code>calloc</code>. I had a look at <a href="https://stackoverflow.com/questions/2565039/how-are-multi-dimensional-arrays-formatted-in-memory">this</a> question, but it doesn't address how memory is allocated in the case of a dynamically allocated two dimensional array.</p>
  
  <p>I was wondering if there was a difference in the memory representation between the following three ways of dynamically allocating a 2D array.</p>
  
  <p><strong>Type 1:</strong></p>
  
  <pre><code>double  **array1;
  int ii;
  
  array1 = calloc(10, sizeof(double *));
  for(ii = 0; ii &lt; 10; ii++) { 
     array1[ii] = calloc(10, sizeof(double));
  }
  // Then access array elements like array1[ii][jj]
  </code></pre>
  
  <p><strong>Type 2:</strong></p>
  
  <pre><code>double  **array1;
  int ii;
  
  array1 = calloc(10 * 10, sizeof(double *));
  // Then access array elements like array1[ii + 10*jj]
  </code></pre>
  
  <p><strong>Type 3:</strong></p>
  
  <pre><code>double  **array1;
  int ii;
  
  array1 = malloc(10 * 10, sizeof(double *));
  // Then access array elements like array1[ii + 10*jj]
  </code></pre>
  
  <p>From what I understand of <code>calloc</code> and <code>malloc</code>, the difference between the last two is that <code>calloc</code> will zero all the elements of the array, whereas <code>malloc</code> will not. But are the first two ways of defining the array equivalent in memory?</p>