sunny wrote:when i wrote that inf =-2147483648
it showed a warning msg & made the value positve.
warning:
"unary minus operator applied to unsigned type, result still unsigned"
but when i modified it like inf=-2147483647-1
then it got AC.
though i used long long but why the value is becoming unsigned if i write like that?
That has to do with how the compiler parses the code. The parser treats it as 2147483648 and then applied unary minus to it. It looks at 2147483648 and figures out that it can't be a signed int (it exceeds 2^31-1), so it assumes that it is unsigned int, and then apply unary minus to it. But unary minus doesn't do what you would expect if the operand is unsigned, namely, it will still return a unsigned value. The fact that inf is declared to be long long, it doesn' matter, because the compiler will always look at right side of assignment first, implicitly determine type using only right hand side, then typecast it to match the type of left side if necessary.
On the other hand, -2147483647-1 is good, since the parser will first read 2147483647, then apply unary minus, then subtract 1 from it. In this case 2147483647 can be a signed int, so it assumes it is from the start.
The common fix to it is to append LL after the integer constant to make the value long long like this: