I have a question on the below piece of code:
void func()
{
int *px1 ;
if(..)
{
int x1;
px1= &x1
}
cout << *px1 ;
}
In the above piece of code, the scope of variable x1 is the if-block but if i store the pointer of x1 to a different variable ( px1 ) and access it later then will it cause a problem.
1. The variable x1 will be allocated on the function stack but when x1 goes out of the scope then is the memory associated to it returned to the free pool.
2. Is the size of function stack fixed in C++ or does it vary as variables are created and destroyed.
thanks
Amit