The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
x
0 votes
59 views

how static affects in this program?

asked in Programming by Active (1.2k points) | 59 views
0
240???

1 Answer

+2 votes
Best answer

 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

answered by Boss (12.6k points)
selected by
0
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.


Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true

37,162 questions
44,731 answers
127,401 comments
43,805 users