title: How do we allocate a 2-D array using One malloc statement
body: <p>I have been asked in an interview how do i allocate a 2-D array and below was my solution to it.</p>
  
  <pre><code>#include &lt;stdlib.h&gt;
  
  int **array;
  array = malloc(nrows * sizeof(int *));
  
  for(i = 0; i &lt; nrows; i++)
  {
      array[i] = malloc(ncolumns * sizeof(int));
      if(array[i] == NULL)
      {
          fprintf(stderr, "out of memory\n");
          exit or return
      }
  }
  </code></pre>
  
  <p>I thought I had done a good job but then he asked me to do it using one <code>malloc()</code> statement not two. I don't have any idea how to achieve it.</p>
  
  <p>Can anyone suggest me some idea to do it in single <code>malloc()</code>?</p>