[Solved] Return value for a int type return statement when there is no return statement present [closed]


You say in a comment:

in case of func() I am getting a return value of 5

What appears to have happened, in practice, on your machine, this time, is that the return value of printf (which is 5, the number of characters printed) came back to func in a register. func has not modified that register prior to its own return, and so main sees what appears to be the return value of func when it checks that same register.

You could confirm or refute this by looking at the disassembled executable code for func.

If this really is what has happened then it is a detail of the calling convention in use, and happenstance that func doesn’t use the register after calling printf. As Kirilenko says the behavior is formally undefined, and you are not entitled to rely on it.

1

solved Return value for a int type return statement when there is no return statement present [closed]