The first declares a variable in an area outside the loop; after the loop ends, the variable will still exist and be used. The second declares the variable in such a way that it belongs to the scope of the loop; after the loop, the variable ceases to exist, preventing accidental / erroneous use of the variable.
C99, ++, Java , . / . , C-, ANSI C .
:
int i;
for ( i = 0; i < 5; i++ ){
printf("%d\n",i);
}
printf("%d\n",i);
:
for (int i = 0; i < 5; i++ ){
std::cout << i << std::endl;
}
std::cout << i << std::endl;