c++ - Adding two positive integers gives negative answer.Why? -
#include<iostream> using namespace std; int main(){ int x = 1967513926; int y = 1540383426; cout<<x+y; return 0; }
sum of above 2 integers 3507897352 < 2^32.so why wrong answer? please help...
an int
signed type, maximum 2^31 - 1 = 2147483647, not 2^32 - 1. do overflow in case.
Comments
Post a Comment