-4

Advanced C question:Why does if return true?

unsigned int i = 8; 
int j = -16;
    if(i+j > 5){
        printf(">5 = %d\n",i+j);
    }else{
        printf("<5 = %d\n",i+j);
    }
haccks
  • 104,019
  • 25
  • 176
  • 264

1 Answers1

1

When a signed int is operated with unsigned int then it is converted to unsigned int. Since -16 can't be represented as unsigned int, maximum value that can be represented ny unsigned int (UINT_MAX) is added to -16.

haccks
  • 104,019
  • 25
  • 176
  • 264