Value of i
would be 10. As of now, if you try to print the value of i
outside the loop, i
is undefined.
When i
was 9, you continued with the loop, for next iteration i
became 10 and condition fails and causes to break the loop. So value of i
is 10. Keep it in mind having stpe statement as ++i
or i++
is not different w.r.t the values that i
would attend. step statement always executes before start of the next iteration.
Following small change would help you to prove the output.
int i,y= 0;
for (i= 0; i<10; ++i)
{
y+= i;
}
printf("%d\n",i);
That being said if you are printing the value of i
within the loop, then you'll get maximum value of i
as 9 on the output. Probably this is what you were doing to conclude the answer as 9.
int y= 0;
for (int i= 0; i<10; ++i)
{
y+= i;
printf("%d\n",i);
}