title: Initialized in a function and is not initialized in main
body: <p>I am trying to allocate memory in a function and I am not sure what I am doing wrong.
  I want this:</p>
  
  <pre><code>int main()
  {
      int* test= 0;
      initialize(test, 10);
      int test2 = test[2];
      delete[] test;
  }
  
  void initialize(int* test, int count)
  {
      test = new int[count];
      for (int i = 0; i &lt; count; i++)
      {
          test[i] = i;
      }
  }
  </code></pre>
  
  <p>But I receive this error: Unhandled exception at 0x770d15de in Robust Simulation.exe: 0xC0000005: Access violation reading location 0x00000008.
  It breaks on line: int test2 = test[2];</p>
  
  <p>but this works:</p>
  
  <pre><code>int main()
  {
      int* test=0;
      test = new int[10];
      for (int i = 0; i &lt; 10; i++)
      {
          test[i] = i;
      }
  
      int test2 = test[2];
      delete[] test;
  }
  </code></pre>
  
  <p>Is there a scoping problem? I thought since I pass it a pointer it would be allocated and I would be able to access it outside of the initialize function.</p>
  
  <p>Thanks for your help</p>