You have to understand the memory mapping for that. I would try to explain. You are returning address of a variable which is out of scope which means you are returning memory address which can be allocated later and now when you call the printf with hi as parameter the returned memory is being filled by some value