Consider the next loop
for(int i = 0; i < 99999999; i++)
{
double d1 = (double)i/10;
double d2 = (double)i/100;
std::cout << d1 * d2 << std::endl;
}
From what I know, the application will allocate and free 16 bytes of memory on the stack (double is 8 bytes on my machine) for every iteration in the loop. Is this true, or are the compilers smart enough to know to free the memory only when the loop ends?
The thing is that variable declaration inside the loop makes the code more readable (imo).