I started to learn c++, and I'm trying to understand the arrow feature in c++. I have this example code, but I'm not getting the desired output.
#include <iostream>
#include <chrono>
struct student {
int age;
};
student* getStudent(int age ){
student person;
student *p;
p = & person;
p->age = age;
return p;
};
int main(int argc, const char * argv[]) {
auto* d = getStudent(29);
std::cout << d->age <<std::endl;
std::cout << d->age <<std::endl;
return 0;
}
Output
29
-2003661472
Program ended with exit code: 0
Why am I getting this undesired output?