C implicit conversion?

Can someone explain to me how

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

outputs "-1". I assume that some implicit conversion is occurring, but I cannot understand it.

+5
source share
1 answer

-2 converts to unsigned integer . This will be equal to UINT_MAX - 1 , which is definitely more than 2 . Consequently, the condition fails and -1 is printed.

+5
source

Source: https://habr.com/ru/post/1242865/


All Articles