title: What does delete command really do for memory, for pointers in C++?
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/1930459/c-delete-it-deletes-my-objects-but-i-can-still-access-the-data">C++ delete - It deletes my objects but I can still access the data?</a><br>
    <a href="https://stackoverflow.com/questions/6441218/can-a-local-variables-memory-be-accessed-outside-its-scope">Can a local variable&#39;s memory be accessed outside its scope?</a>  </p>
  </blockquote>
  
  
  
  <p>I do not understand what <code>delete</code> really does when I want to free memory allocated with <code>new</code>. In C++ Premiere book it is written:</p>
  
  <blockquote>
    <p>This removes the memory to which ps pointer points; it doesn’t remove the
    pointer ps itself. You can reuse ps, for example, to point to another new allocation. You 
    should always balance a use of new with a use of delete; otherwise, you can wind up with 
    a memory leak—that is, memory that has been allocated but can no longer be used. If a 
    memory leak grows too large, it can bring a program seeking more
    memory to a halt.</p>
  </blockquote>
  
  <p>So as I understand <code>delete</code> must delete the value in the memory to which pinter points. But it doesn't. Here's my experiment:</p>
  
  <pre><code>int * ipt = new int;   // create new pointer-to-int
  
  cout &lt;&lt; ipt &lt;&lt; endl;   // 0x200102a0, so pointer ipt points to address 0x200102a0
  cout &lt;&lt; *ipt &lt;&lt; endl;  // 0, so the value at that address for now is 0. Ok, nothing was assigned
  *ipt = 1000;     // assign a value to that memory address
  cout &lt;&lt; *pt &lt;&lt; endl;   // read the new value, it is 1000, ok
  cout &lt;&lt; *((int *) 0x200102a0) &lt;&lt; endl;   // read exactly from the address, 1000 too
  
  delete ipt;   // now I do delete and then check
  cout &lt;&lt; ipt &lt;&lt; endl;  // 0x200102a0, so still points to 0x200102a0
  cout &lt;&lt; *ipt &lt;&lt; endl;  // 1000, the value there is the same
  cout &lt;&lt; *((int *) 0x200102a0) &lt;&lt; endl;    // 1000, also 1000 is the value
  </code></pre>
  
  <p>So what does <code>delete</code> really do?</p>