Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Returning pointer to local variable (http://www.go4expert.com/forums/returning-pointer-local-variable-t1828/)

raviinroorkee_7 7Nov2006 19:43

Returning pointer to local variable
 
Hi,
we should avoid returning a pointer to local variable. If one wants to do that then either variable has to be declared static or varable has to be allocated dynamically. In later case calling function should take care of deallocating the variable to avoid memory leaks.
Can anyone tell me why it works in case of dynamically allocation and static declaration and why not in case of simple local variable?

shabbir 8Nov2006 10:22

Re: Returning pointer to local variable
 
You have posted it as an Article under the Article / Source code section. I have moved it to the Queries and Discussion forum.

Duplicate of Returning pointer to local variable. Thread closed.


All times are GMT +5.5. The time now is 04:28.