1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Returning pointer to local variable

Discussion in 'C' started by raviinroorkee_7, Nov 7, 2006.

Thread Status:
Not open for further replies.
  1. raviinroorkee_7

    raviinroorkee_7 New Member

    Joined:
    Nov 7, 2006
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    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?
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,283
    Likes Received:
    364
    Trophy Points:
    83
Thread Status:
Not open for further replies.

Share This Page