posted 18 years ago
Hi amrita,
The answer is yes, the code compiles fine but the results is not as expected.
Once int variables can hold 31 bits plus one for sign, ints can accept values from -2^31 ~ 2^31 - 1. So all values between -21474883648 and 21474883647 are supposed to fit in an int variable.
However, when you try to assign the value 21474883647 + 1, the left most bits are discarded to fit this new number.
So, if you check the value for i variable after line 8 it is -2147483648.
What about if you change your code to 21474883647 + 2 ? The value for variable now is -2147483647.
If you change to 21474883647 + 3, its value is -21474883646 and so on ...
"If someone asks you to do something you don't know how to, don't tell I don't know, tell I can learn instead." - Myself