0

This is my code:

using namespace std;

// if memory is alloted statically then you can't access memory address after the function has returned and its stack is gone.

int* function(int x)
 {
  int *x_ptr = &x;
  return x_ptr;
 }

int main()
{
 int x=10;
 int *x_ptr = function(x);
 cout<<*x_ptr<<endl;
}
Ken White
  • 123,280
  • 14
  • 225
  • 444

1 Answers1

0

you can't access memory address after the function has returned

Correct.

The behaviour of the program is undefined.

eerorika
  • 232,697
  • 12
  • 197
  • 326