If you really want the value to lose value, you might call another function with at least a few lines of code before doing printf, referring to the location. Most likely, your value will be written by then.
But then again, as already mentioned, this behavior is undefined. You can never predict when (or if at all) it will fail or change. But you cannot rely on the fact that it "changes or remains unchanged" and encodes the application with any of these assumptions.
What I'm trying to illustrate is that when you call the function again after returning from the previous one, another activation record is pushed onto the stack, most likely over the previous record, including the variable whose value you got through the pointer.
No body actually collects garbage or performs the memset 0 function after the function and data are out of scope.
source share