Hey i m reading tutrial about rucursion and got code whish isnt complicated or anything but i dunno why it prints the way it does
/* recur.c -- recursion illustration */
#include <stdio.h>
void up_and_down(int);
int main(void)
{
up_and_down(1);
return 0;
}
void up_and_down(int n)
{
printf("Level %d: n location %p\n", n, &n); /* 1 */
if (n < 4)
up_and_down(n+1);
printf("LEVEL %d: n location %p\n", n, &n); /* 2 */
}
here it prints
Level 1: n location 0022FF60
Level 2: n location 0022FF40
Level 3: n location 0022FF20
Level 4: n location 0022FF00
LEVEL 4: n location 0022FF00
LEVEL 3: n location 0022FF20
LEVEL 2: n location 0022FF40
LEVEL 1: n location 0022FF60
first i know why it prints from 1 to 3 but see here it keeps calling itself till number is smaller than 4 right then after it finishes it goes back to that printf after that if statement whish should print the normal i whish is 1 but it doesnt it prints 4 4 3 2 1 why it got decremented there nowhere in the code where it said i-1 even when the function called itself even if we alrdy specified i as 1 and function calling itself somehow decremented it should when i==3 that if statement will terminate whish will print then orginal i ?