How does this foo function works?

  1. You are calling the function foo on a.
  2. 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 to foo in foo and see if you get anything different.
  3. sum is changing because you are doing sum = sum + k and passing it to all the future calls.
  4. When n eventually becomes 0 due to repeated divisions, the last call to foo starts returning and following them all the previous calls start returning after printing the digit they had extracted using n % 10

Browse More Popular Posts

Leave a Comment