title: How to pass Dynamic Array by reference C++
body: <p>I'm having trouble understanding how to pass a dynamic array by reference in C++.</p>
  
  <p>I've recreated the problem in this small isolated code sample:</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  
  void defineArray(int*);
  
  int main()
  {
      int * myArray;
      defineArray(myArray);
  
      /** CAUSES SEG FAULT*/
      //cout&lt;&lt;(*(myArray)); //desired output is 0
      return 0;
  }
  
  void defineArray(int*myArray)
  {
      int sizeOfArray;
      cout&lt;&lt;"How big do you want your array:";
      cin&gt;&gt;sizeOfArray;
  
      /** Dynamically allocate array with user-specified size*/
      myArray=new int [sizeOfArray];
  
      /** Define Values for our array*/
      for(int i = 0; i &lt; sizeOfArray; i++)
      {
          (*(myArray+i))=i;
          cout&lt;&lt;(*(myArray+i));
      }
  }
  </code></pre>