0
Can anyone explain why it's printing "panni" instead of "-23 23"
int main() { unsigned int i = 23; signed char a = -23; if(i>a) printf("%d %d",a,i); else if(i<a) printf("panni"); return 0; }
3 Answers
+ 2
You are actually comparing signed and unsigned values. Because 'i' is at first place, C convert 'a' to an unsigned value...
As you know, -23 > 23 (if you don't understand why, search for the binary representation of a negative value), so it is false.
If you're working in C, try to cast 'i' to a signed value.
+ 1
I don't know if that's the issue but I'd use if / else instead of if / else if
Maybe you're missing an else statement?
Then again I'm not familiar with signed / unsigned comparison
0
Théophile can you elaborate what value it (a) will be converted ?? And how the conversion happens?
If there any study link please share. It'll be more helpful