So, I got an example in a book:
int * func()
{
int A[3][3] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
return (int*)A;
}
void main(void)
{
int *a = func();
cout << *(a + 2*3 + 1);
system("PAUSE");
}
I tried running this and its working fine.
My question is we are providing stack memory inside func() routine which should be available (compiler can assign some other variable at same address) after the exit from func(). Is it a correct way? I think this could lead to UnDefined Behaviour sometime..