Writing a program to count the number of recursive calls
<p>Suppose I have the following recursive function, that returns the nth fibonacci number:</p>

<pre><code>private int fib(int n) {
    if(n == 1) return 0;
    if(n == 2) return 1;
    return fib(n - 1) + fib(n - 2);
}
</code></pre>

<p>How would I write a piece of code to return the total number of recursive calls made by this function ? I was thinking of introducing a count parameter as in <code>fib(int n, int count = 0)</code> or a static variable inside <code>fib</code> as <code>static int count = 0</code> and increment count right before the recursive call. I had no success with either of these two approaches as I couldn't return <code>count</code>. Is there a way to get the total number of recursive calls without modifying the original function ?</p>