This should be the minimum value of the integer, i.e. 0x80000000, if it is 32-bit, because it is the only non-zero number that remains unchanged when negated.
#include <stdio.h> main() { int data = 0x80000000; if(data!=0 && data==-data) { printf("AMAZING"); } }
Result:
AMAZING
As Richard Pennington correctly pointed out, this works because of two additions to represent negative numbers. The largest representable positive number is one smaller in absolute value than the largest negative number, so if you try to negate the largest negative number, it overflows int and wraps, returning the same number.
For computers that use one additional option , each represented negative value of a number can also be represented without overflow so that this puzzle has no solution.
Mark byers
source share