title: Free double pointer using a function
body: <p>So I have created and allocated memory for a double pointer using the following function:</p>
  
  <pre><code>void mallocDoubleArr(double ***arr, int size)
  {
      printf("Here: %d", 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>And I called the function using:</p>
  
  <pre><code>    double **G; //Create double pointer to hold 2d matrix
  
      mallocDoubleArr(&amp;G, numNodes);
  </code></pre>
  
  <p>Now my question is how would I write a function to free the memory?</p>
  
  <p>I tried something like this:</p>
  
  <pre><code>void freeDoubleArr(double ***arr, int size)
  {
      int i, j;
  
      for (i = 0; i &lt; size; i++)
          for (j = 0; j &lt; size; j++)
              free((arr)[i]);
      free(arr);
  }
  </code></pre>