Returning pointer to local variable

raviinroorkee_7's Avatar, Join Date: Nov 2006
Newbie Member
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's Avatar, Join Date: Jul 2004
Go4Expert Founder
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.