title: C programming initialize 2D array dynamically
body: <p>I'm doing something silly here and I can't put my finger on exactly what: </p>
  
  <pre><code> void init_data(double **data, int dim_x, int dim_y) {
  
      int i,j,k;
  
      data = (double **) malloc(sizeof(double) * dim_x);
      for (k = 0; k &lt; dim_y; k++) {
          data[k] = (double *) malloc(sizeof(double) * dim_y);
      }
  
      for (i = 0; i &lt; dim_x; i++) {
          for (j = 0; j &lt; dim_y; j++) {
              data[i][j] = ((double)rand()/(double)RAND_MAX);
          }
      }
  }
  </code></pre>
  
  <p>And in main() I do the following: </p>
  
  <pre><code>double **dataA;
  int dim = 10; 
  init_data(&amp;dataA, dim, dim);
  </code></pre>
  
  <p>But then right after that when I try printing the data the program crashes: </p>
  
  <pre><code>int i,j;
      for(i=0;i&lt;dim;i++)
          for(j=0;j&lt;dim;j++)
              printf("%d\n", dataA[i][j]);
  </code></pre>
  
  <p>What am I missing? </p>
  
  <p>Thanks</p>