title: What does Visual Studio do with a deleted pointer and why?
body: <p>A C++ book I have been reading states that when a pointer is deleted using the <code>delete</code> operator the memory at the location it is pointing to is &quot;freed&quot; and it can be overwritten.  It also states that the pointer will continue to point to the same location until it is reassigned or set to <code>NULL</code>.</p>
  <p>In Visual Studio 2012 however; this doesn't seem to be the case!</p>
  <p><strong>Example:</strong></p>
  <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  
  int main()
  {
      int* ptr = new int;
      cout &lt;&lt; &quot;ptr = &quot; &lt;&lt; ptr &lt;&lt; endl;
      delete ptr;
      cout &lt;&lt; &quot;ptr = &quot; &lt;&lt; ptr &lt;&lt; endl;
  
      system(&quot;pause&quot;);
  
      return 0;
  }
  </code></pre>
  <p>When I compile and run this program I get the following output:</p>
  <pre><code>ptr = 0050BC10
  ptr = 00008123
  Press any key to continue....
  </code></pre>
  <hr />
  <p>Clearly the address that the pointer is pointing to changes when delete is called!</p>
  <p>Why is this happening?  Does this have something to do with Visual Studio specifically?</p>
  <p>And if delete can change the address it is pointing to anyways, why wouldn't delete automatically set the pointer to <code>NULL</code> instead of some random address?</p>