Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C implicit conversion?

Can someone explain to me how

printf("%d", -2<2u?1:-1);

prints out '-1'. I assume there is some kind of implicit conversion going on but I can't seem to grasp it.

like image 768
Nebeski Avatar asked Feb 12 '16 12:02

Nebeski


1 Answers

-2 is getting converted to unsigned integer. This will be equal to UINT_MAX - 1, which is definitely greater than 2. Hence, the condition fails and -1 is printed.

like image 136
CinCout Avatar answered Sep 28 '22 13:09

CinCout