title: How do I initialize a two-dimensional array in C
body: <p>I am trying to initialize two copies of the same two-dimensional arrays in C.  However, only one stores the correct data:</p>
  
  <pre><code>    //convert 1D array to 2D array
  double** myA = malloc(n*sizeof(double*));
  for (j=0;j&lt;n;j++)
      myA[j]=&amp;a[j*n];
  
  double** myS = (double **) malloc(n*sizeof(double*));
  for (i=0; i&lt;n; i++)
      for (j=0; j&lt;n; j++){
          myS[i] = (double *) malloc(n*sizeof(double));
          myS[i][j] = myA[i][j];
      }
  
  printf("A:\n");
  print_matrix(myA,n);
  printf("S:\n");
  print_matrix(myS,n);
  </code></pre>
  
  <p>I want to initialize two copies of A.  One as myA and the other as myS.  However, here is my output:</p>
  
  <pre><code>A:
  0.000000 1.000000 2.000000 3.000000 4.000000 
  1.000000 1.414214 2.236068 3.162278 4.123106 
  2.000000 2.236068 2.828427 3.605551 4.472136 
  3.000000 3.162278 3.605551 4.242641 5.000000 
  4.000000 4.123106 4.472136 5.000000 5.656854 
  
  S:
  -0.000000 -0.000000 -0.000000 -0.000000 4.000000 
  -0.000000 -0.000000 -0.000000 -0.000000 4.123106 
  -0.000000 -0.000000 -0.000000 -0.000000 4.472136 
  -0.000000 -0.000000 -0.000000 -0.000000 5.000000 
  -0.000000 -0.000000 -0.000000 -0.000000 5.656854 
  </code></pre>
  
  <p>Why are all the columns but the last <code>-0.000000</code>?</p>