title: Segfault when deleting pointer
body: <p>I've been experiencing segfaults when running some C++ code.  I've isolated the problem to a line in the program that deletes a pointer.  Here's a simple example that produces the same error:</p>
  
  <pre><code>int main()
  {
    int* pointer=0;
    int number = 3;
  
    pointer = &amp;number;
    delete pointer;//This line causes a segmentation fault
    pointer=0;
  
    return 0;
  }
  </code></pre>
  
  <p>A slight modification produces code that will work as expected:</p>
  
  <pre><code>int main()
  {
    int* pointer=new int(3);
  
    delete pointer;//This line now works
    pointer=0;
  
    return 0;
  }
  </code></pre>
  
  <p>Can someone explain why the first causes a segfault and the second does not?  I know the pointer isn't invalid, since it's been assigned to the address of the number variable.</p>