title: Dynamic allocate 2d array and init it (segmentation fault)
body: <p>I am learning C and I tried to allocate memory for a 2D array (the dimensions of the array I get them from the user),  but I get a segmentation fault after I try to init it. My code is this:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  int main()
  {
     printf("give the dimensions!\n");
     int row,col,i,j; 
     int **myArray;
  
     printf("\nrows = ");
     scanf("%d", &amp;row);
     printf("columns = ");
     scanf("%d", &amp;col);
     myArray = malloc(row*sizeof(*myArray) + col*sizeof(**myArray));
  
     printf("Init the array: \n");
     for (i = 0; i &lt; row; i++)
     {
         for (j = 0; j &lt;col ; j++)
         {
             scanf("%d", &amp;myArray[i][j]);
         }
     }
  
     return 0;
  }
  </code></pre>
  
  <p>If I change the array as <code>myArray[2][2]</code> and omit the malloc statement it works fine..</p>