title: Why is it possible to delete an uninitialized pointer in a destructor, but not in main?
body: <p>please check the destructor of the foo function below. If I delete the p pointer then it runs fine. But if I do the same in main program then I get an error. Why does it allow me to do this in a destructor?</p>
  
  <p>P.S. I know that there's no point in deleting the pointer because there is no dynamically allocated memory.</p>
  
  <pre><code>class foo
  {
    int* p;
  
  public:
    ~foo()
    {
      delete p; // runs fine
      cout &lt;&lt; "Destructor run \n";
    }
  };
  
  
  int main()
  {
  
  int* p;
  delete p; // This will cause error "uninitialized local variable 'p' used "
  
  foo test; // destructor runs fine at the end of the program
  
    return 0;
  }
  </code></pre>