#include <stdio.h>
int f(int n)
{
static int r = 0;
if (n <= 0) return 1;
r=n;
return f(n-1) + r;
}
int main() {
printf("output is %d", f(5));
return 0;
}
Output obtained was
output is 6
So does this mean that always return statement is executed left to right and value of static variable r will be the latest value after it has been updated by all recursive calls f(4), f(3), f(2), f(1)?
However, output is same if I change the return statement as return r + f(n-1); which implies that it always takes latest updated value irrespective of left to right order. Is this assumption correct?