This is the code that I have a question about:
int* getPtrToFive() {
int x = 5;
return &x;
}
int main() {
int *p = getPtrToFive();
cout << *p << endl; // ???
}
The lecture slides say that *p wouldn't give a valid result because as getPtrToFive is returned, x goes out of scope. However, I thought that getPtrToFive would already contain the value of 5, which would validate *p? Is it because of the pointer trying to direct me to getPtrToFive which has an out of scope x?