Suppose we have the following:
void print()
{
int a; // declaration
a = 9;
cout << a << endl;
}
int main ()
{
print();
}
>
As for construction of objects:
Construction happen at the point of declaration, and the destructor is called when the object goes out of scope.
But construction of objects and when memory is allocated do not need to coincide.
Just as destruction of objects and when memory is deallocated do not need to coincide.
As for when the memory on the stack is actually allocated:
I don't know, but you could check via the following code:
void f()
{
int y;
y = 0;//breakpoint here
int x[1000000];
}
By running this code you can see where the exception happens, for me on Visual Studio 2008 it happens on entry of the function. It never reaches the breakpoint.