无符号数加法
#include <stdio.h>
#include "stdafx.h"
#include <iostream>
using namespace std;
int uadd_ok(unsigned x,unsigned y) {
cout << x << endl;
cout << y << endl;
unsigned result = x + y;
return result >= x;
}
int main() {
unsigned x = 1;
unsigned y = 4294967295;
cout << uadd_ok(x, y)<<endl;
}
如果s没有溢出,我们能够肯定s>=x。另一方面,如果s确实溢出了,我们就有s=x + y - 。假设y< ,我们就有y - < 0,因此s = x + (y - ) < x.