Nebeski
Nebeski

Reputation: 610

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.

Upvotes: 5

Views: 161

Answers (1)

CinCout
CinCout

Reputation: 9619

-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.

Upvotes: 5

Related Questions