How does C++ integer division work for limit and negative values?
<p>I am facing some strange results with integer division in C++. I am trying to calculate this: <strong>-2147483648 / -1</strong>.</p>

<p>What I get is 3 different results in 3 different scenarios:</p>

<pre><code>int foo(int numerator, int denominator) {
    int res = numerator / denominator; // produces SIGFPE, Arithmetic exception interrupt

    cout &lt;&lt; res &lt;&lt; endl;
}

int main() {
    int res = -2147483648 / -1;
    cout &lt;&lt; res &lt;&lt; endl;               // prints -2147483648
    cout &lt;&lt; -2147483648 / -1 &lt;&lt; endl;  // prints 2147483648
    foo(-2147483648, -1);
    return 0;
}
</code></pre>

<p>Why does the integer division operation produces different results in different situations?</p>