title: C++ how to correctly free memory?
body: <pre><code>int main(){
      int *a = new int[5];
      int *b = new int[10];
      int *c;
      for (int i = 0; i &lt; 5; ++i){
          a[i] = i * i;
      }
      for (int i = 0; i &lt; 10; ++i){
          b[i] = 50;
      }
      c = a;
      a = b;
      delete[]b;
      delete[]c;
      return 0;
  }
  </code></pre>
  
  <p>After the execution of code above, has the memory <code>a</code> originally pointed to been freed?</p>
  
  <p>If not, how to free correctly?</p>
  
  <p>~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~</p>
  
  <p>pointer <code>a</code> has to be reserved for other uses, so it is prohibited to delete a directly.</p>
  
  <p>the purpose of this code is to access the memory belonging to <code>b</code> originally via <code>a</code> and free the memory a used to possess correctly.</p>