Seg Fault Depending on Order of Pointer Assignment : <p>Consider the following code:</p>

<pre><code>#include &lt;iostream&gt;

int main()
{
  // ok by itself     
  int *ptr1;
  int a = 3;
  *ptr1 = a;

  // ok by itself        
  int *ptr2 = new int(4);
  delete ptr2;
}
</code></pre>

<p>This results in a seg fault, and I can't figure out why.  If either of the blocks are commented, it's okay.  If the second block is placed above the first block, it's also okay.  What's going on here?</p>
