I have a recursive function that I am troubleshooting. I want to output the recursion depth...i.e. how many times the function calls itself.
If I use a static variable that increments at the top of the function and decrements at the bottom.
Will this accurately give me the depth level?
recurse()
  {
  static int depth = 0;
  depth++;
  /*
  do stuff
  recurse()
  */
  depth--;
  return return_value;
  }
                recurse(int depth = 0){
    ....
    recurse(depth+1);
}
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With