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

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -