#include<stdio.h>
main()
{
unsigned x=1;
signed char y=-1;
clrscr();
if(x>y)
printf("x>y");
else
printf("x<=y");
}
A signed character has an increased value from -128 to 127. So the expected out put should have been ‘x>y’, but it isn’t. The compiler gives the output – “x<=y”. Can you explain why?
In the comparison the
signed chargets converted to anunsigned intand thus looks like a really big value. I would expect the compiler to warn you – i.e. something in the lines “comparing signed and unsigned stuff is confusing”.This conversion is mandated under “Relational operators”: