Most answers said that undefined behaviour can include "appearing" to work, and they are right.
Alexander Malakhov's answer gave implementation details which are kind of common and explain why your situation appeared to work, but he made a slight misstatement. He wrote "which is alright while execution since you do not use this arg" but meant "which appeared to be alright while execution since you do not use this arg".
But be warned, your code still is undefined behaviour. It printed what you wanted AND it transfered the balance of your bank account to mine. I thank you.
(SO style says this should be a comment but it's too long. I made it CW though.)