title: When allocating a dynamic array, are the previous elements deleted?
body: <p>Title says it all more or less. When I need an (for the sake of this example) integer array for an unknown amount of values I know I can change it's size using <code>new *array = new int[size]</code>. Now my question is: If I have an array of a certain size, but I need to make it bigger, can I just use the new operator to expand it and will it still have all previously stored elements or would it be smarter to create a whole new array with a dynamic size, copy all elements from the previous array into the new one and <code>delete[]</code> the old array. Basically just swapping between the two arrays, whenever I need a new size.</p>
  
  <p>Specifically I am asking whether or not this piece of code would work in the way it's intended to work</p>
  
  <pre><code>for(int i = 1; i &lt; 10; i++){
  int *array = new int[i];
  array[i-1] = i;
  }
  </code></pre>
  
  <p>My assumption is that this array will first be the size of 1 and store the value 1 at index 0. Then it will reallocate its size to 2 and store the value to at index 1 and so on until i is 9.</p>
  
  <p>I guess to rephrase my question a bit better: Does an array initialized with new have to be populated with elements or will it copy the elements it had from before using the operator?</p>