Just out of curiosity. For example the code below having the same variable "i" use in a different loop
1 2 3 4 5 6 7 8 9
for(int i = 0; ...)
{
// do something
}
for(int i = 0; ...)
{
// do something again
}
I know from experience that it will work just fine but what about the memory allocated? Will it be the same or will allocate a new one? Is it right to use the same variable again or just declare a different variable for a different for loop.
You can safely use the same symbol in different loops.
The declaration of int i exists within the loop and the compiler must enforce that it cannot be accessed anywhere but within the loop.
Whether or not int i shares the same memory however, shouldn't be your concern. It might, or it might not. The compiler may optimize your code. Or it might not. You should treat them as if they're different integers.