title: Dynamically changing array size in C++
body: <p>I need to transform an array from <code>{4, 2 ,5}</code> to <code>{4, 2, 5, 4, 2, 5}</code>. Here's my output: <code>{4, 2, 5, 3.21143e-322, 0, 2}</code>, which is obviously incorrect. But I cannot seem to figure out the issue in my logic. Perhaps another perspective can find that issue.</p>
  
  <hr>
  
  <p>This is my code:</p>
  
  <pre><code>void repeatArray(double* oldArray, int size) {
      int newSize = size * 2;
      double* newArray = new double[newSize];
      for (int i = 0; i &lt; size; i++) {
          newArray[i] = oldArray[i];
      }
      for (int i = 0; i &lt; size; i++) {
          newArray[size+i] = oldArray[i];
      }
      oldArray = newArray;
      delete [] newArray;
  }
  
  int main() {
      double* oldArray = new double[3];
      oldArray[0] = 4;
      oldArray[1] = 2;
      oldArray[2] = 5;
      repeatArray(oldArray, 3);
      for (int i=0; i&lt;6; i++)
          cout &lt;&lt; oldArray[i] &lt;&lt; endl;
      delete []oldArray;
      return 0;
  }
  </code></pre>