I have a basic question:- 1.>int i=2147483648; The above code will generate the compile time error for the value being one more than the positive range.But.... 2.>int i=-(-2147483648); The above code will compile successfully.and the output will be '-2147483648'. Why does this things compiles b'coz after negating those minus signs the value is still out of int's range. Help me Golu Jain
Paul Anilprem
Enthuware Software Support
Ranch Hand
Joined: Sep 23, 2000
Posts: 2912
posted
0
The reason is the range of signed types is not symetric. For. eg. int's range is -2^31 to 2^31-1. You can see that, it can store 1 negative number more than positive no. Now, at runtime when you negate the largest -ive no., it's positive value falls outside the range by 1. So, in effect you get the same negative number. HTH, Paul. ------------------ Get Certified, Guaranteed! (Now Revised for the new Pattern) www.enthuware.com/jqplus