If the code is really as you showed, it is probably pretty pointless. Most compilers I've seen allocate space for all local variables when entering a function and free it when leaving a function. However, there are several other possibilities.
If what you showed as bar was an object of some type of class (especially something with a destructor), the destructor will work when you exit the area, although the space was not released until a later time.
Another possibility is that there were actually two internal areas:
int main() {
In this case, the space for local variables will be allocated when entering main - but, some variables and other variables will (usually) share the same space. That is, the allocated space will be enough to accommodate the larger of the two, but it will not (usually) be the sum of the two, as you would use if you defined all the variables in the main .
source share