2 votes 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 asked Sep 3, 2015 • edited Nov 22, 2015 by Pragy Agarwal debanjan sarkar 6.5k views answer comment Share Follow See all 0 reply Please log in or register to add a comment.
1 votes 1 votes 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 See all 1 1 comment reply debanjan sarkar commented Sep 3, 2015 reply Follow Share how two zero's are coming before 1?? pls explain this part... 0 votes 0 votes Please log in or register to add a comment.
1 votes 1 votes 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 See all 0 reply Please log in or register to add a comment.
0 votes 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 See all 1 1 comment reply debanjan sarkar commented Sep 3, 2015 reply Follow Share ok got it thank u.. 0 votes 0 votes Please log in or register to add a comment.
0 votes 0 votes Answer is Option A sdpshaw answered Sep 3, 2015 sdpshaw comment Share Follow See all 0 reply Please log in or register to add a comment.