C: Comparing two long integers (very strange)
Posted
by Kyle
on Stack Overflow
See other posts from Stack Overflow
or by Kyle
Published on 2010-03-20T15:33:42Z
Indexed on
2010/03/20
15:41 UTC
Read the original article
Hit count: 116
Hi,
I have following situation (unix) :
x is a long and has value 300
y is a long and has value 50000
if (x <= y) printf("Correct.");
if (x > y) printf("Ouch.");
Now I always get "Ouch". That means the program keeps telling me that 300 is greater than 50000!
It only works again when I do
if ((int)x <=(int) y) printf("Correct.");
if ((int)x > (int)y) printf("Ouch.");
So what is wrong with the comparison operators?
© Stack Overflow or respective owner