Storing number larger than INT_MAX in an int
<p>Can someone explain this C++ behaviour to me?</p>

<pre><code>for (int i=0;i&lt;3;++i){
    int x;
    std::cin &gt;&gt; x;
    std::cout &lt;&lt; x &lt;&lt; std::endl;
}
</code></pre>

<p>If I input a number larger than INT_MAX (like 124124124124124) only ONCE, this outputs:</p>

<pre><code>2147483647
2147483647
2147483647 
</code></pre>

<p>My best guess is that it recognizes my input is a number, but it slices because <code>x</code> can only fit up to <code>2147483647</code>. What I don't understand is why after inputting that big number only ONCE, the input "overflows" to the other inputs, and prints <code>2147483647</code> three times, then ends the program.</p>