title: Dynamic array, passing addresses
body: <p>I want to make a function which has in parameter an array of two dimensions that I dynamically allocated, the problem is that I don't know how to build my function.</p>
  
  <p>Here is what I have in my main(N_MAX is defined as 300):</p>
  
  <pre><code>int i;
  int **Bord = NULL;
  
  Bord = malloc(N_MAX * sizeof(*Bord));
  if(Bord == NULL)
  {
      printf("Error while allocating memory to an array");
      free(Bord);
      return -1;
  }
  for(i = 0; i &lt; N_MAX; i++)
  {
      printf("%d\n", i);
      Bord[i] = malloc(N_MAX * sizeof(*(Bord[i])));
      if(Bord[i] == NULL)
      {
          printf("Error while allocating memory to an array");
          while(i != 0)
          {
              free(Bord[i]);
              i--;
          }
          free(Bord);
          return -1;
      }
  }
  </code></pre>
  
  <p>I've tried to do something with an array that is not dynamically allocated but it's really bad. When I want to debug the function I have the watches that works (I have the right number in my array) but the program doesn't work (error: invalid type argument of unary '*' (have 'int'))</p>
  
  <p>I've already did some searches on Google but I can't find a topic with "dynamic allocation" and "pass by reference", if it exists please let me know.</p>
  
  <p>How to buid this function?</p>