title: c++ delete pointer issue, can still access data
body: <p>I don't really understand why are those pointer accessible ... any help appreciated</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  class Wicked{
  public:
      Wicked() {};
      virtual ~Wicked() {};
  
      int a;
      int b;
  };
  
  
  class Test
  {
  public:
      Test() {};
      virtual ~Test() {};
  
      int c;
  
      Wicked * TestFunc()
      {
          Wicked * z;
          c = 9;
          z = new Wicked;
          z-&gt;a = 1;
          z-&gt;b = 5;
          return z;
      };
  };
  
  int main()
  {
      Wicked *z;
  
      Test *t = new Test();
      z = t-&gt;TestFunc();
  
      delete z;
      delete t;
  
      // why can I set 'z' when pointer is already destroyed?
      z-&gt;a = 10;
  
      // why does z-&gt;a print 10?
      std::cout &lt;&lt; z-&gt;a &lt;&lt; std::endl;
  
      // why does t-&gt;c exist and print correct value?
      std::cout &lt;&lt; t-&gt;c &lt;&lt; std::endl;
  
      //------------------------------------------------------
  
      int * p = new int;
      *p = 4;
  
      // this prints '4' as expected
      std::cout &lt;&lt; *p &lt;&lt; std::endl;
  
      delete p;
  
      // this prints memory address as expected
      std::cout &lt;&lt; *p &lt;&lt; std::endl;
  
      return 0;
  }
  </code></pre>