title: Deleting memory allocated with pointers (dynamic array)
body: <p>If I create 2 pointers: </p>
  
  <pre><code>int *pointer;
  int *temp;
  </code></pre>
  
  <p>and I allocate memory for one of them in this case <code>temp</code>:</p>
  
  <pre><code>temp = new int [ size ]; //size = 6
  </code></pre>
  
  <p>I then point my second pointer <code>pointer</code> to the same memory location:</p>
  
  <pre><code>pointer = temp;
  </code></pre>
  
  <p>If I want to deallocate temp:</p>
  
  <pre><code>delete [ ] temp;
  </code></pre>
  
  <p>it won’t let me… And I say it won’t let me because if I do a loop to populate elements of <code>temp</code> it will still let me populate it even after I used <code>delete [ ] temp;</code>. I am trying to understand what happens here so now my questions are:</p>
  
  <ol>
  <li>When I did <code>delete [ ] temp;</code> was the memory deallocated (I think not because I had another pointer pointing to that location) and if it wasn’t… does that means the <code>delete [ ] temp;</code> had no effect?</li>
  <li>Is it possible to deallocate memory if more than one pointer is pointing to that memory location?</li>
  <li>Lets say that i am done with both pointers and I want to free the memory, what would be the best way to do it? I cannot do <code>delete [ ] pointers;</code> because I never allocated memory for pointer I just pointed it to the <code>temp</code> memory address.</li>
  </ol>
  
  <p>Note: I know that I can use vectors I am just trying to understand memory management while using pointers.</p>