Firstly, your function wedgic
returns a pointer to its local variable foo
. The pointer becomes invalid immediately after the function wedgic
terminates. Any attempts to use the returned pointer value lead to undefined behavior. In other words, you program produces no meaningful results. The behavior is undefined. Whatever you see there (7 7 7
or whatever else) is just an accident with no meaningful explanation.
Secondly, your program make only two attempts to output anything. Yet you claim that it somehow outputted three numbers. This is highly unlikely, even for a program with undefined behavior. It is either that your claim about the output is false, or you posted fake code. When you ask question about the results produced by some code, please, post real code.