0 votes 0 votes void abc() { auto int a; static int s; a=s++; printf("%d%d",a,s); if(a<=2) abc(); printf("%d%d",a,s); } void main() { abc(); abc(); } how many times printf will execute?? saipriyab asked Nov 24, 2017 saipriyab 750 views answer comment Share Follow See all 10 Comments See all 10 10 Comments reply SHUBHAM SHASTRI commented Nov 24, 2017 reply Follow Share 4 times ?? 0 votes 0 votes hs_yadav commented Nov 24, 2017 i edited by hs_yadav Nov 24, 2017 reply Follow Share i think o/p:- (0,1) (1,2) (2,3) (3,4) .... (3,4) (2,4) (1,4) (0,4) (4,5) (4,5) (10 times) ????? 0 votes 0 votes saipriyab commented Nov 24, 2017 reply Follow Share I got 8 times (0,1) (1,2) (2,3) (3,4) (3,4) (2,4) (1,4) (0,4) 0 votes 0 votes saipriyab commented Nov 24, 2017 reply Follow Share @hs_yadav how 10 times how (4,5) (4,5) can u explain??? 0 votes 0 votes joshi_nitish commented Nov 24, 2017 reply Follow Share yes it would be 10 times, 8 times on 1st call to abc(); and 2 times on 2nd call to abc(); 0 votes 0 votes Red_devil commented Nov 24, 2017 reply Follow Share 10 times..because the second abc() will also execute it 2 times 0 votes 0 votes SHUBHAM SHASTRI commented Nov 24, 2017 reply Follow Share how 1st one goes 8 times ...i didnt get 0 votes 0 votes SHUBHAM SHASTRI commented Nov 24, 2017 reply Follow Share oh! ..i got it... 0 votes 0 votes hs_yadav commented Nov 24, 2017 reply Follow Share @ saipriyab after the completion of first abc(); s=4 after the second call oof abc(); a=s++(a=4) s=5) and print(4,5) then a<=2 print(4,5)..... 1 votes 1 votes saipriyab commented Nov 24, 2017 reply Follow Share yes I got it 1 votes 1 votes Please log in or register to add a comment.
0 votes 0 votes o/p 0,1 1,2 2,3 3,4 3,4 2,4 1,4 0,4 4,5 4,5 reason is static variable initialize only once . Nitesh Choudhary answered Nov 24, 2017 Nitesh Choudhary comment Share Follow See all 2 Comments See all 2 2 Comments reply abhishek tiwary commented Nov 25, 2017 reply Follow Share after 3,4 how the value of a get decremented?? 0 votes 0 votes abhishek tiwary commented Nov 25, 2017 reply Follow Share ok i got it 0 votes 0 votes Please log in or register to add a comment.