title: Write a function to malloc double pointer
body: <p>I need to write a function that creates a double pointer using malloc. </p>
  
  <p>This is how I declared my double pointer as I normally would:</p>
  
  <pre><code>double **G; //Create double pointer to hold 2d matrix
  
  *G = malloc(numNodes * sizeof(double*));
  for(i = 0; i &lt; numNodes; i++)
  {
      G[i] = malloc(numNodes*sizeof(double));
      for (j = 0; j &lt; numNodes; j++)
      {
          G[i][j] = 0;
      }
  }
  </code></pre>
  
  <p>Now I tried replacing it with:</p>
  
  <pre><code>double **G;
  mallocDoubleArr(G, numNodes);
  </code></pre>
  
  <p>With the function being:</p>
  
  <pre><code>void mallocDoubleArr(double **arr, int size)
  {
      int i, j;
  
      *arr = malloc(size * sizeof(double*));
  
      for(i = 0; i &lt; size; i++)
      {
          arr[i]= malloc(size*sizeof(double));
          for (j = 0; j &lt; size; j++)
          {
              arr[i][j] = 0;
          }
      }
  }
  </code></pre>
  
  <p>Why doesn't this work?</p>