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 is a protocol in c?
Explain what is the concatenation operator?
What is the data segment that is followed by c?
What are different types of pointers?
#include
How can you tell whether a program was compiled using c versus c++?
What is meant by high-order and low-order bytes?
Where can I get an ansi-compatible lint?
What is the difference between mpi and openmp?
What are the 5 data types?
Why doesnt long int work?
How pointers are declared?
What is d scanf?
which of the following is not a character constant a) 'thank you' b) 'enter values of p, n ,r' c) '23.56E-o3' d) all of the above
How can I copy just a portion of a string?