- You are calling the function
foo
ona
. - That is the order since you are printing AFTER you are processing the rest of the number. Try moving the call to
printf
before the call tofoo
infoo
and see if you get anything different. sum
is changing because you are doingsum = sum + k
and passing it to all the future calls.- When
n
eventually becomes0
due to repeated divisions, the last call tofoo
starts returning and following them all the previous calls start returning after printing the digit they had extracted usingn % 10
4
solved How does this foo function works?