1 votes 1 votes void ab() { auto int a; static int s= 5; a = ++s; printf("%d%d",a,s); if(a<= 7) ab(); printf("%d%d",a,s); } void main() { ab(); } According to me answer should be- 667788887766 but the answer is - 667788887868. Please explain Programming in C recursion programming-in-c + – parasghai28 asked Jul 8, 2018 • edited Dec 27, 2023 by Hira Thakur parasghai28 1.0k views answer comment Share Follow See all 2 Comments See all 2 2 Comments reply Shubhgupta commented Jul 8, 2018 reply Follow Share static variable store in static part of memory and once changed then retain their value throughout the program. So S will print 8 only after ending of each activation record. 0 votes 0 votes Naveen Kumar 3 commented Jul 8, 2018 reply Follow Share 667788887868 is correct answer. since, s is static & static variables are stored data area of memory, which is not destroyed. So, finally updated value of 's' (which is 8) will be printed, while coming back recursively. However, a is auto so, it is stored in stack. so, each time local stack values will be taken for 'a' & stack is destroyed, while coming back recursively. 0 votes 0 votes Please log in or register to add a comment.
Best answer 2 votes 2 votes Ans-667788887868 a is local variable and s is static variable so scope of local variable is local and it will destroy after function is over and scope of static variable is throughout the program. Anil Ji answered Jul 8, 2018 • selected Jul 8, 2018 by parasghai28 Anil Ji comment Share Follow See all 6 Comments See all 6 6 Comments reply Show 3 previous comments altamash commented Jul 9, 2018 reply Follow Share thanks @Anil Ji 0 votes 0 votes Rajucse commented Jul 16, 2018 reply Follow Share Anil ji you are so great 0 votes 0 votes Hira Thakur commented Dec 27, 2023 reply Follow Share I did not get it. in last how 887868 is printed? when $8\leq7$ this condition is false then what happens? 0 votes 0 votes Please log in or register to add a comment.