Hi,
I have a real beginner question for you all.
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 haveCode:double * GetSalary() { double salary = 26.48; double *HourlySalary = &salary; return HourlySalary; }
aren't you then going to have ptr pointing to an address in memory that will be holding different data?Code:main() { double * ptr = GetSalary(); }
Also, when GetSalary() returns, does the pointer HourlySalary get destroyed just like any other primitive upon return?
Thanks



LinkBack URL
About LinkBacks



CornedBee