Hi,
I have a real beginner question for you all.
Code:
double * GetSalary()
{
double salary = 26.48;
double *HourlySalary = &salary;
return HourlySalary;
}
I found the example above on a website. I thought that a double declared in a function is allocated space on the run-time stack and is destroyed after the function returns. So if you then have
Code:
main()
{
double * ptr = GetSalary();
}
aren't you then going to have ptr pointing to an address in memory that will be holding different data?
Also, when GetSalary() returns, does the pointer HourlySalary get destroyed just like any other primitive upon return?
Thanks