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

Explain what is the benefit of using an enum rather than a #define constant?

728


What is echo in c programming?

561


Define circular linked list.

573


What is call by value in c?

562


how much salary u want ? why u join in our company? your domain is core sector why u prefer software ?

1507






What are the functions to open and close file in c language?

732


What is a pointer and how it is initialized?

611


What are identifiers and keywords in c?

575


What is an expression?

660


What Is The Difference Between Null And Void Pointer?

647


What is modeling?

649


What is assignment operator?

630


Is linux written in c?

603


Which type of language is c?

656


What is the difference between declaring a variable by constant keyword and #define ing that variable?

2705