title: What if I delete an array once in C++, but allocate it multiple times?
body: <p>Suppose I have the following snippet.</p>
  
  <pre><code>int main()
  {
      int num;
      int* cost;
      while(cin &gt;&gt; num)
      {
          int sum = 0;
          if (num == 0)
            break;
  
          // Dynamically allocate the array and set to all zeros
          cost = new int [num];
          memset(cost, 0, num);
          for (int i = 0; i &lt; num; i++)
          {
              cin &gt;&gt; cost[i];
              sum += cost[i];
          }
          cout &lt;&lt; sum/num;
      }
  `  `delete[] cost;
      return 0;
  }
  </code></pre>
  
  <p>Although I can move the <code>delete</code> statement inside the while loop 
  for my code, for understanding purposes, I want to know what happens with the code as it's written. Does C++ allocate different memory spaces each time I use operator <code>new</code>?</p>
  
  <p>Does operator <code>delete</code> only delete the <em>last</em> allocated <code>cost</code> array?</p>