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

how static affects in this program?

asked in Programming by Active (1.3k points) | 67 views

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:

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

Related questions

+3 votes
1 answer
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
48,691 questions
52,776 answers
68,389 users