This is the line of code in C.
The condition of loop here is ++i.
So how does compiler decide which condition to consider because here other two appear as conditions?
char i=0;
for(i<=5&&i>-1;++i;i>0)
printf("%d",i);
output
1234..127-128-127....-2-1
The
forstatement works like this:translates to
So your code changes from:
to:
As you can see, lines marked with
XandZare completely useless. Therefore:This means it will print from 1 up to whenever result of
++iis zero.If
charin your compiler is signed, then the behavior is left to implementation, even though most likely it will overflow to a negative value and work its way up to zero.If
charis positive, this will print positive values up to where it overflows back to 0.