unsigned u = 10;
int i = -42;
std::cout<<u+i<<std::endl;
for a 32 bit integer it prints 4294967264 But I am not able to understand it how it works.
unsigned u = 10;
int i = -42;
std::cout<<u+i<<std::endl;
for a 32 bit integer it prints 4294967264 But I am not able to understand it how it works.
looks like its treating i as an unsigned integer. i is stored as '11111111111111111111111111010110' in twos compliment form. This is equivalent to 4294967254 when interpreted as an unsigned integer. when you add 10 to it, you get the final answer of 4294967264
4294967264 - 2^32 = -32. Does that look familiar? It should, since -32 = 10 - 42