title: C++ Passing a dynamicly allocated 2D array by reference
body: <p>This question builds off of a previously asked question:
  <a href="https://stackoverflow.com/questions/529109/c-pass-by-reference-multidimensional-array-with-known-size">Pass by reference multidimensional array with known size</a></p>
  
  <p>I have been trying to figure out how to get my functions to play nicely with 2d array references.  A simplified version of my code is:</p>
  
  <pre><code>    unsigned int ** initialize_BMP_array(int height, int width)
      {
         unsigned int ** bmparray;
         bmparray = (unsigned int **)malloc(height * sizeof(unsigned int *));
         for (int i = 0; i &lt; height; i++)
         {
          bmparray[i] = (unsigned int *)malloc(width * sizeof(unsigned int));
         }
        for(int i = 0; i &lt; height; i++)
          for(int j = 0; j &lt; width; j++)
          {
               bmparray[i][j] = 0;
          }
      return bmparray;
      }
  </code></pre>
  
  <p>I don't know how I can re-write this function so that it will work where I pass bmparray in as an empty unsigned int ** by reference so that I could allocate the space for the array in one function, and set the values in another.</p>