Is variable declared inside loop a local variable?

I just wonder if I declared a variable inside loop like while and for, is this variable a local one inside this loop?

E.g.:

for (int i=0; i < 10; i++)
{
............
}

Can I still use this "i" after the loop?

Thanks.


Last edited on
no its only available inside the curly brackets of the forloop
Thanks for reply. Just have another question, if I code like this:

for (i=0; i < 10; i++)
{
int a =0;
...........
}

Does "a" be declared in each loop ?
yes a gets initialized to zero each time that loop runs.
Whatever is declared in those for(){<here>} will run as many times as the loop runs

btw i is not initialized in that for loop. i must be init somewhere before or inside the () for that to compile
Last edited on
Topic archived. No new replies allowed.