361 views

1 Answer

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

selected by

Related questions

3 votes
3 votes
3 answers
1
Laxman Ghanchi asked May 19, 2023
1,113 views
#include<stdio.h void print(int n) { printf("Hello "); if(n++ == 0) return ; print(n); n++; } int main() { void print(); print(-4); }How many times printf execute?? And H...
0 votes
0 votes
1 answer
2
Laxman Ghanchi asked May 19, 2023
658 views
#include<stdio.h>void print(int n){ printf("Hello "); if(n++ == 0) return ; print(n); n++;}int main(){ void print(); print(-4);}
0 votes
0 votes
1 answer
3
0 votes
0 votes
0 answers
4
abhinowKatore asked Dec 5, 2022
603 views
What will be the return value of the below function, if it is called a sample(4)? int sample(int x){ if( x == 0 || x ==2) return 1; return (sample( x) * (x ));}