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


Please Help Members By Posting Answers For Below Questions

What language is windows 1.0 written?

571


What is the purpose of type declarations?

673


What is a macro, and explain how do you use it?

621


What does volatile do?

561


What is void main ()?

605






When is the “void” keyword used in a function?

826


Write a code to remove duplicates in a string.

623


What is the purpose of scanf() and printf() functions?

713


How is = symbol different from == symbol in c programming?

607


which is conditional construct a) if statement b) switch statement c) while/for d) goto

732


What are the three constants used in c?

539


What is a example of a variable?

545


Explain what is the benefit of using enum to declare a constant?

582


What are the key features in c programming language?

607


What are qualifiers?

613