Possible Duplicate:
Best way to detect integer overflow in C/C++
i have tried to implement simple program which tests if overflow occurs during integer addition:
#include <climits>
#include <iostream>
#include <string>
using namespace std;
string overflow(long a,long b){
return ((a+b)>UINT_MAX)?"true":"false";
}
int main(){
long a, b;
cout << "enter a and b: ";
cin >> a >> b;
string m = overflow(a,b);
cout << m;
return 0;
}
UINT_MAX=65535
so i have entered 65535 and 20 but it wrote false why?