This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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
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