I do not understand how this example can work:
double * GetSalary() {
double salary = 26.48;
return &salary;
}
main() {
cout << *GetSalary();
}
salaryis a local variable in GetSalary(), therefore, after returning from this function, this cell can be overwritten by another function. I do not see how it is ever possible to work with a pointer to a local variable (not instanciated to a bunch).
source
share