title: Does an object destruction invalidate pointers?
body: <p>In the code below, is <code>s</code>still pointing to valid memory after s1 is destroyed ? If yes, how does that work ? If no, anything we can do to avoid it ?</p>
  <pre><code>#include &lt;iostream&gt;
  struct S {
      S(){std::cout&lt;&lt;&quot;S()\n&quot;;}
      ~S(){std::cout&lt;&lt;&quot;~S()\n&quot;;}
  };
  
  int main(){
      S *s;
      {
          S s1;
          s=&amp;s1;
      }
  }
  
  //output:
  //S()
  //~S()
  </code></pre>