consider the following C code
main()
{
int i=3,x;
while(i>0)
{
x=func(i);
i--;
}
int func(int n)
{
static sum=0;
sum=sum+n;
return(sum);
}
the final value of x is
Answer Posted / manishsoni
we know that the static can't change its value but in
functions:-
"This inside a function static variable retains its value
during various calls."
{
static sum=0; at i=3;sum=0+3;save or retains sum=3
sum=sum+n; at i=2;sum=3+2:save or retains sum=5
return(sum); at i=1;sum=5+1;save or retains sum=6
}
so the final value is 6;
if here we declare sum as auto type then it didn't retains
its value or print 1;sum=0+1;
Is This Answer Correct ? | 5 Yes | 0 No |
Post New Answer View All Answers
What language is windows 1.0 written?
What is the purpose of type declarations?
What is a macro, and explain how do you use it?
What does volatile do?
What is void main ()?
When is the “void” keyword used in a function?
Write a code to remove duplicates in a string.
What is the purpose of scanf() and printf() functions?
How is = symbol different from == symbol in c programming?
which is conditional construct a) if statement b) switch statement c) while/for d) goto
What are the three constants used in c?
What is a example of a variable?
Explain what is the benefit of using enum to declare a constant?
What are the key features in c programming language?
What are qualifiers?