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);
}
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);
}
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.