2 2 votes void myfunc(int X){ if(X > 0) myfunc( --X ); printf("%d", X); } int main(){ myfunc(5); return 0; } 0,0,1,2,3,4 4,3,2,1,0 4,3,2,1,0,0 0,1,2,3,4 Programming in C programming-in-c + – debanjan sarkar 7.6k views answer comment Share Follow Print 0 reply Please log in or register to add a comment.
1 1 vote A.0,0,1,2,3,4 --- 0 printed twice because of --x statement @ if condition for fun(0) 0 is printed and for fun(1) 0is printed because value x is decremented before fun(0) fun call starts to execute! Ravi Raaja answered Sep 3, 2015 Ravi Raaja comment Share Follow See 1 comment 1 1 comment reply debanjan sarkar commented Sep 3, 2015 reply Follow flag how two zero's are coming before 1?? pls explain this part... 0 0 replyShare Please log in or register to add a comment.
1 1 vote Key point which u have to note here is that there is no braces after the if statement therefore the first statement written after it would only fall into the if portion so myfunc(0) when called would simply print 0 ,so 2 0's would be printed. it won't enter into the if check condition and rest explanation is already given by others ,My intention was to just highlight the braces portion. radha gogia answered Oct 18, 2015 radha gogia comment Share Follow 0 reply Please log in or register to add a comment.
0 0 votes A. 0,0,1,2,3,4 recursive call sequence -myfun(5)--> myfun(4)--> myfun(3)--> myfun(2)--> myfun(1)-->myfun(0) so,myfun(0) prints a 0 then myfun(1) prints 0 again as 1 in decremented first in similiar way then 2 ,3 and lastly 4 get printed. Saurav answered Sep 3, 2015 Saurav comment Share Follow See 1 comment 1 1 comment reply debanjan sarkar commented Sep 3, 2015 reply Follow flag ok got it thank u.. 0 0 replyShare Please log in or register to add a comment.
0 0 votes Answer is Option A sdpshaw answered Sep 3, 2015 sdpshaw comment Share Follow 0 reply Please log in or register to add a comment.
0 0 votes It's tail recursion problem.. so the output is 0,0,1,2,3,4 Hira Thakur answered Nov 17, 2015 Hira Thakur comment Share Follow 0 reply Please log in or register to add a comment.