title: Allocate a dynamic 2d-array by passing it to another function by reference
body: <p>This question builds off of two previously asked questions: <a href="https://stackoverflow.com/questions/529875/c-passing-a-dynamicly-allocated-2d-array-by-reference">C++ Passing a dynamicly allocated 2D array by reference</a> &amp; <a href="https://stackoverflow.com/questions/529109/c-pass-by-reference-multidimensional-array-with-known-size">C - Pass by reference multidimensional array with known size</a></p>
  
  <p>I was trying to allocate memory for a 2d-Array using the answers of these previous questions, but the memory never been allocated and I receive a BAD_ACCESS error every time a try to access the array!</p>
  
  <p>This is what I have:</p>
  
  <pre><code>const int rows = 10;
  const int columns = 5;
  
  void allocate_memory(char *** maze); //prototype
  
  int main(int argc, char ** argv) {
    char ** arr;
    allocate_memory(&amp;arr) //pass by reference to allocate memory
    return 0;
  }
  
  void allocate_memory(char *** maze) {
    int i;
    maze =  malloc(sizeof(char *) * rows);
    for (i = 0; i &lt; rows; ++i)
        maze[i] = malloc(sizeof(char) * columns);
  }
  </code></pre>