title: How to access a dynamic array in two different functions c++
body: <p>I need to access a dynamic array in two different functions. The changes made to it in one need to transfer over to the other.</p>
  
  <p>These are the functions:</p>
  
  <pre><code>void populate(int size, int *ptr)
  {
      ptr = new int[size];
      for (int i = 0; i &lt; size; i++)
      {
          ptr[i] = rand() % 51;
      }
  }
  
  void display(int size, int *ptr)
  {
      for (int i=0; i &lt; size; i++)
      {
          cout &lt;&lt; ptr[i] &lt;&lt; endl;
      }
  }
  </code></pre>
  
  <p>it is called in the main as </p>
  
  <pre><code>int* ptr = NULL;
  </code></pre>