Reputation: 463
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
}
Upvotes: 0
Views: 1041
Reputation: 53006
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.
Upvotes: 2