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

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -