I have a code in C++.
int* func(int n) {
    int* v= &n;
    return v;
}
int main()
{
    int* c = func(5);
    int* k = func(9);
    cout<<*c;
}
This code returns a 9 instead of a 5. However, when I change the func to
int* func(int n) {
    int* v= new int(n);
    return v;
}
This returns a 5 as expected. Is there a reason why the 1st one doesn't work but the 2nd one does?
 
    