I am trying to understand recursion but stuck on a very basic concept. The following code
int fun(int i) {
if(i>1) {
printf("%d---\n",i);
fun(i-1);
printf("%d***\n",i);
}
else {
return i;
}
}
int main() {
// Write C code here
int i=fun(5);
printf(">>%d",i);
return 0;
}
which gives the output
5---
4---
3---
2---
2***
3***
4***
5***
>>5
but code
int fun(int i){
if(i>1){
//printf("%d---\n",i);
fun(i-1);
// printf("%d***\n",i);
}
else {
return i;
}
}
gives
>>1
can anyone please explain the flow control?