[Solved] Recursive function : print statement before/after function call


Because it is a recursive function. Let’s say you call it with n=3

For the first case you would get:

printSeriesInReverse(3)
3 > 0 // YES
  prints 3
  printSeriesInReverse(2)
  2 > 0 // YES
    prints 2
    printSeriesInReverse(1)
    1 > 0 // YES
      prints 1
      printSeriesInReverse(0)
      0 > 0 // NO
      // End of recursion

Final output: 321

For the second case you would get:

printSeriesInReverse(3)
3 > 0 // YES
  printSeriesInReverse(2)
  2 > 0 // YES
    printSeriesInReverse(1)
    1 > 0 // YES
      printSeriesInReverse(0)
      0 > 0 // NO
      // End of recursion
      prints 1
    prints 2
  prints 3

Final output: 123

1

solved Recursive function : print statement before/after function call