0 votes 0 votes how static affects in this program? Programming in C recursion + – chandra sai asked Nov 18, 2017 chandra sai 361 views answer comment Share Follow See 1 comment See all 1 1 comment reply pawan kumarln commented Nov 18, 2017 reply Follow Share 240??? 0 votes 0 votes Please log in or register to add a comment.
Best answer 2 votes 2 votes For Static variable memory creation and memory initialization only once, when we are calling the function the first time(one-time declaration and use many time )The static keyword in C are initialized as 0 if not initialized explicitly. Without static keyword above program, work likes auto variable which default value is garbage.Every time when we call the function it will reinitialize. In above program without static keyword, every time f is initialized as garbage value whereas when using the static keyword the first time it initialized as 0(default value) then use function call value. plz refer here: https://gateoverflow.in/159796/programming https://gateoverflow.in/36225/output-of-this-code Hira Thakur answered Nov 18, 2017 selected Nov 19, 2017 by srestha Hira Thakur comment Share Follow See 1 comment See all 1 1 comment reply chandra sai commented Nov 19, 2017 reply Follow Share in the solution, the value of f in rec(x-1) is used in rec(x) and ....f in rec(x) is used in rec(x+1) and so on.. my doubt is that as f is static , f should give the same value for both rec(x) and rec(x+1)?but this is not happening. what is wrong with my approach? please explain. 0 votes 0 votes Please log in or register to add a comment.