This behavior is undefined, so anything is possible - including the possibility that your code "works" as expected. Your compiler should have warned about this - it is important to take into account warnings such as errors, and fix any problems encountered before testing your code.
Compilers use stack or processor registers to return values from functions. When a return absent, the data does not fit into the return value space. However, the data that you planned to return may already be in the register or on the stack only in the right place, so the call code demonstrates the behavior that you expect. It remains undefined, however.
source share