Test for overflow in integer addition
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/199333/best-way-to-detect-integer-overflow-in-c-c">Best way to detect integer overflow in C/C++</a>  </p>
</blockquote>



<p>i have tried to implement simple program which tests if overflow occurs during integer addition:</p>

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

using namespace std;

string overflow(long a,long b){
    return ((a+b)&gt;UINT_MAX)?"true":"false";
}

int main(){
    long a, b;
    cout &lt;&lt; "enter a and b: ";
    cin &gt;&gt; a &gt;&gt; b;
    string m = overflow(a,b);
    cout &lt;&lt; m;

    return 0;
}
</code></pre>

<p><code>UINT_MAX=65535</code>  so  i have entered  65535  and 20 but it wrote false why?</p>
