You use %d
, so printf interprets the value as signed.
Comparison to zero (>=0) of unsigned is always true.
So, while values are from 10 to 0, the output is ok (109876543210). After that the value becomes huge positive (maximum value, for 32bit int it is 0xFFFFFFFF
). Comparison to 0 is true, so the loop continues. But in printf
0xFFFFFFFF
produces -1
since %d
is used. Then the loop continues to 0xFFFFFFFE
which is -2
but still >= 0
as unsigned.
Use %u
.