GeeksforGeeks » C/C++ Programming Questions
A C Puzzle
(4 posts)-
int data; // Initialize data during run time if ( data == -data && data!=0) printf ("Miracle!!");Will miracle ever print ?
-
Yes. When 'data' is on its left extreme of the number scale.
-
@venki you mean to say when data is = -32467 ?
-
@Mario, small correction. It is -32768 on 16-bit platforms and -2147483648 on 32-bit platforms.
In general the range is -2^(N-1) to 2^(N-1) - 1. The left extreme will have same pattern even when numerically negated. This is due to the fact that 2's complement form of any number which is exactly power of 2 will result in same number. And, we can't have 2^(N-1) on the +ve side of the scale. Ofcourse, zero is special... always.
In case of floating point numbers we can have -ve zero and +ve zero. The bit pattern of floating point numbers is different.
Reply
You must log in to post.