First of all, there is no recursion in your program because there is no function at all that calls itself: neither func()
calls func()
nor main()
calls main()
.
Since the variable num
in the function func()
is declared as static
, all the calls to the function func()
share a single copy of the variable num
. This variable is initialized only once: the first time the function func()
gets called. Its value is kept between calls (this variable is not allocated on the stack).
In the following loop:
for (fun(); fun(); fun())
printf("%d ", fun());
func()
is called once at the very beginning and 3 times on every loop iteration.
Every time func()
gets called, num
is decremented by one. For that reason, each time the value returned by func()
is displayed it is decremented by three
with respect to the last displayed value.