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
code for quick sort?
Tell me with an example the self-referential structure?
write a C program: To search a file any word which starts with ?a?. If the word following this ?a? starts with a vowel.Then replace this ?a? with ?a? with ?an?. redirect with the output onto an output file.The source file and destination file are specified by the user int the command line.
What do you mean by dynamic memory allocation in c? What functions are used?
if a is an integer variable, a=5/2; will return a value a) 2.5 b) 3 c) 2 d) 0
What are the differences between new and malloc in C?
Is there a way to switch on strings?
What is the difference between struct and union in C?
What will be the outcome of the following conditional statement if the value of variable s is 10?
What is the purpose of the statement: strcat (S2, S1)?
How can I access an I o board directly?
find out largest elemant of diagonalmatrix
What does 3 mean in texting?
explain what are actual arguments?
What is the difference between constant pointer and constant variable?