The reason is that not all pathes of your function
f()
return a value explicitly.
But there is a (hidden) value returned:
You are calling
f()
as last call in your code so that the return value from that function call is returned. Because the function is called iteratively until the parameter
a
is zero, the return value of the last call is zero. Then that value is passed back to each next upper call so that the final return value is always zero.
[EDIT]
To make it better understable. Your code behaves similar to:
return f(a/10);
Return values of integral type (like
int
) are passed in a specific platform dependant register. When not having a
return
statement, the register contains still the return value from the last call.
If you would have called another function as last call, the value would be different:
int f(int a)
{
f(a/10);
printf("s=%d\n", s);
}
With the above, the return value of the
printf()
function is returned (the number of characters actually printed).
[/EDIT]