title: Copying part of 2D array into another 2D array in C
body: <p>I want to write C code that takes a block of a 2D array and copies it into another 2D array by using the <code>memcpy</code> function. In the particular code I have included, I have tried to copy the last 3 columns of the 2x4 array <code>matrix</code> into the 2x3 array <code>mat_copy</code>. </p>
  
  <pre><code>double matrix[2][4] = {{0, 1, 2, 3}, {4, 5, 6, 7}};
  double mat_copy[2][3];
  double sz = sizeof(mat_copy)/2;
  
  for (int i = 0; i &lt; 2; i++) {
      memcpy(&amp;mat_copy[i][1], &amp;matrix[i][1], sz);
  }
  </code></pre>
  
  <p>I'm getting the output: <code>[0, 1, 2; 3, 5, 6]</code> instead of <code>[1, 2, 3; 5, 6, 7]</code>. How does the <code>memcpy</code> function choose which addresses to copy once you give the initial pointer in memory? I know my error has to do with addressing the 2D arrays, but I don't know how to change it. </p>