Hy! Sorry for my bad english, anyway the questions is:
I have this code in objective-c:
unsigned int a = 1;
int b = -2
if (b < a);
I expect true and instead the result of the if(b < a)
is false, why?
C automatically converts -2 into an unsigned int in the comparison. The result is that the comparison is actually (4294967294 < 1), which it is not.
You are comparing signed to unsigned. The signed value is promoted to unsigned, which results in a large number (0xFFFFFFFD
I think) which is definitely bigger than 1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With