I think your confusion has to do with how for loops operate. Here you can find a description. The important detail is to understand the every time the loop
for (init_statement; condition; iteration_expression){ statement;}
is run, the order of the operations are equivalent to the following:
{
init_statement
while ( condition ) {
statement
iteration_expression ;
}
}
It means that i
is decreased after the block of the for loop is executed.
In the case of int
, when i = 0
, it runs the code inside it and then, it decreases the value. That way, the next iteration of the loop fails the condition, so it does not print i = -1
.
Regarding unsigned int
it never goes negative. If you debug it you will see how, once it reaches 0, instead of having the value -1 that value is converted to unsigned and the result is a big positive value. In particular, 4294967295, if unsigned int
is 32 bits. You can see the details in this other question.
And that's why you have "unexpected behaviour" (not for the compiler), because suddenly you have a really big positive number, so you probably have an infinite loop in your hands.