Similar code. One works, one crashes. Why? : <p>I was working on a problem for Project Euler using C++ in Code::Blocks 10.05 and found my program to be crashing in a strange place: the initialization.  Here is a code snippet that reproduces the problem.</p>

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

using namespace std;

vector&lt;deque&lt;uint32_t&gt; &gt; f;

int main()
{
    deque&lt;uint32_t&gt; p;
    deque&lt;uint32_t&gt;::iterator dit1,dit2;
    p.push_back(0);
    p.push_back(1);
    f.push_back(p);
    cout &lt;&lt; f.back().size() &lt;&lt; endl;
    cout &lt;&lt; "f= ";
    for(dit1==f.back().begin();dit1!=f.back().end();dit1++) cout &lt;&lt; *dit1 &lt;&lt; " ";
    cout &lt;&lt; "Checkpoint" &lt;&lt; endl;
    return 0;
}
</code></pre>

<p>Before posting here, I tried a test program to see if I could figure out the problem.</p>

<pre><code>#include &lt;iostream&gt;
#include &lt;deque&gt;
#include &lt;vector&gt;
using namespace std;


int main(void)
{
    uint64_t i;
    deque&lt;uint32_t&gt; d;
    vector&lt;deque&lt;uint32_t&gt; &gt; vd;
    deque&lt;uint32_t&gt;::iterator it;
    for(i=1;i&lt;=5;i++) d.push_back(i);
    vd.push_back(d);
    for(it=vd.back().begin();it!=vd.back().end();it++) cout &lt;&lt; *it &lt;&lt; " ";
    return 0;
}
</code></pre>

<p>The first program crashes while the second correctly reproduces the deque.  Besides variable names, the only major difference I see is the first program uses a global variable and the test program uses a local variable.  So why does the first program crash in the for loop while the second does not?</p>
