unsigned int and signed char comparison

后端 未结 4 839
死守一世寂寞
死守一世寂寞 2020-11-27 07:36

I am trying to compare an unsigned int with a signed char like this:

int main(){
  unsigned int x = 9;
  signed char y = -1;
  x < y ? printf(\"s\") : pri         


        
4条回答
  •  粉色の甜心
    2020-11-27 08:07

    Ran the following code:

    int main(){
      unsigned int x = 9;
      signed char y = -1;
      printf("%u\n", (unsigned int)y);
      x < (unsigned int)y ? printf("s") : printf("g");
      return 0;
    }
    

    The output is:

    4294967295
    s
    

    After a casting, y takes a very large value. That is why output is s.

提交回复
热议问题