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
Explain what is the benefit of using an enum rather than a #define constant?
What is echo in c programming?
Define circular linked list.
What is call by value in c?
how much salary u want ? why u join in our company? your domain is core sector why u prefer software ?
What are the functions to open and close file in c language?
What is a pointer and how it is initialized?
What are identifiers and keywords in c?
What is an expression?
What Is The Difference Between Null And Void Pointer?
What is modeling?
What is assignment operator?
Is linux written in c?
Which type of language is c?
What is the difference between declaring a variable by constant keyword and #define ing that variable?