Is this acceptable by all C Standards?
for (int i=0; i<n; i++) {
// do stuff
}
Or should I write it like this just to be sure it works everywhere?
int i;
for (i=0; i<n; i++) {
// do stuff
}
Is this acceptable by all C Standards?
for (int i=0; i<n; i++) {
// do stuff
}
Or should I write it like this just to be sure it works everywhere?
int i;
for (i=0; i<n; i++) {
// do stuff
}
No, it's valid since C99 only. If you want your code to be valid under old standards use
int i;
for (i = 0 ; i < n ; i++)
And also, read this comment by @JoachimPileborg it complements well this answer.
i is now that of the enclosing block, not just the for loop.break from a loop and use the value of i after the loop to see if it completed naturally. But if i has gone out of scope that is not possible.