I have this recursive function in C,and i'm trying to understand why it's printing the way it does:
void rec(int x, int y){
if (x == y)
return;
rec(x--, y+1);
printf("%3d%6.2f\n", x, (float) y);
}
I know that ther output for rec(8,4) is:
7 7.00
7 6.00
7 5.00
7 4.00
why the X
value stays 7?as i understand it, the x--
should happen only after the line it's written.If not,why the value stays 7 and not decreasing?
Also why the y
value is decreasing?because it starts printing when the recursion is stopped?
I'm pretty new to C,and not used to all the little details that require attention(i'm coming from java)
thanks for any help!