Hey, here is something you should know: Those thingies separated by ';' characters in the head of the for loop are expressions, all three of them! Both for loops compile but this should give a warning:
for(i=0;i++;i<5)
because the last expression doesn't have a side effect (ie: it does not change anything) and your compiler is smart! As I said all three thingies are expressions but the first is used for initialization, the second is for pre-testing before every execution of the loop-body, and the third expression is executed after each execution of the loop-body.
This c code:
for (expr1; expr2; expr3)
{
code_in_the_body_of_for_loop
}
Can be written this way:
expr1
while (1) {
if (!expr2) break;
code_in_the_body_of_for_loop
expr3; }
In your case when the pre-test expression (expr2) is i++ the for loop never executes the body code because the value of i++ is zero so it breaks out from your for loop immediately! You compiler should also warning if expr3 is just
i<5
because you normally never write a statement like
i<5;
in your code, do you? :D