Remember: In C, when you are operating between two different types, the low byte length type converts to the high self length type, and the symbol converts to the unsigned type.
Examples are as follows:
#include <stdio.h>
void func (void)
{
int i = 1;
unsigned char c1 = 1;
Signed char c2 =-1;
if (C2 > i) {
printf ("\r\n-1 > 1");
}
else{
printf ("\r\n-1 <= 1");
}
if (C2 > C1) {
printf ("\r\n-1 > 1");
}
else {
printf ("\r\n-1 <= 1");
}
printf ("\ n");
}
int main ()
{
func ();
return 0;
}
Output:
-1 <= 1
-1 <= 1
When C2 and I are compared, because C2 is signed 8 bits, I is unsigned 32 bits, according to the C language rules, C2 is converted into 32 bits, that is, 1 of the complement, it will come to the -1>1 conclusion.
The next -1<1 situation is that C2 is converted into unsigned 8-bit integers, or 255,255, so greater than 1.
The above article on the C language type of recessive transformation of the pit is small to share all the content of everyone, hope to give you a reference, but also hope that we support the cloud habitat community.