autmatic storage duration
sudhanshu631,
No. When the function call is made, only a copy of the address is passed to funcy(). When 'y' is destroyed, the information it contains (which is the address of x) may be lost but noting gets cleared as a result of this loss. You can test this fairly quickly by displaying the value of x before -- and -- after the call to to funcy(). Of course, if funcy() modifies y (which actually contains the address of x) then x will be modified. Whatever value funcy() assigns to to y will remain that way after the function completes and y is destroyed.
As a side note, depending on the compiler, there is a good chance 'y' will exist only on the stack. It may never exist in code space. Thus when main() calls funcy() the address of x is placed on the stack. Funcy() uses this stack location on every access to y. It may never get copied from the stack to a new location. When funcy() is finished, this address for x is popped off the stack but it is not used. Rather, the memory claimed by the stack is simply freeded and can be reused next time something else must be pushed onto the stack. The stack location which contained y (address of x) will remain unchanged until the next function call when something else is placed on the stack. When this memory location on the stack is later overwritten, only copy of address of x is destroyed, not the actual memory location containing x.
Ken
|