In a recursive function, how can default parameters be used to track state across recursive calls?

  • Utilize default parameter values to maintain state
  • Use default parameters only for base cases
  • Default parameters are not suitable for recursive functions
  • Recursive functions cannot use default parameters
In a recursive function, default parameters can be leveraged to maintain state across different recursive calls. This allows you to pass and update values without explicitly passing them in each recursive call. For example, consider a factorial function where the default parameter keeps track of the current product.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *