Can anyone tell me how is it printing '012' ? | Sololearn: Learn to code for FREE!
+ 1

Can anyone tell me how is it printing '012' ?

#include<stdio.h> void fun(int n) { if(n>0) { fun(--n); printf("%d",n); } } int main() { int a=3; fun(a); return 0; }

3rd Jan 2019, 10:15 AM
Sahil Bhakat
Sahil Bhakat - avatar
4 Answers
+ 1
I do understand how is it happening like when n becomes 0 after all the decrements it return back to fun (1) and prints the the value of n which is 0 and after that it goes to fun (2) where it prints 1 and after that in fun(3) it prints 2 Then the compiler gets out of the function fun ()😁
3rd Jan 2019, 12:31 PM
Sahil Bhakat
Sahil Bhakat - avatar
0
#Rewa Mathur I just wanted to know after n becomes 0 What happens next ? Thanks by the way i got my answer
3rd Jan 2019, 12:20 PM
Sahil Bhakat
Sahil Bhakat - avatar
0
Gordie I agree with you i need to see more deeply in the recursive functions
3rd Jan 2019, 12:58 PM
Sahil Bhakat
Sahil Bhakat - avatar
0
I just somehow forgot that the compiler will come back to printf after the decrementing processes are done
3rd Jan 2019, 1:05 PM
Sahil Bhakat
Sahil Bhakat - avatar