title: What are 'Bad Ptr' mean in Visual C++?
body: <p>For C++, when we check whether the pointer is valid or not, usually we do the following:</p>
  
  <pre><code>if (p == NULL){
       // error handling
  }
  </code></pre>
  
  <p>However, in VC++, even <strong>p</strong> is not NULL (aka 0), it is <strong>0x00000004</strong>, also means <strong>Bad Ptr</strong>. and then cause exception, we know this address is protected, can not be overwritten.</p>
  
  <p>I have searched similar questions here, but I did not get the answer.   </p>
  
  <p>My questions are:</p>
  
  <ol>
  <li>when the Bad Ptr happened, why not just set this pointer to 0?</li>
  <li>since the value of Bad Ptr is not zero, how to check whether the pointer is valid or not in VC++?</li>
  </ol>