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
Q.1 write aprogram to stack using linklist o insert 40 items? Q.2 write a program to implement circular queue with help of linklist?
int i=10; printf("%d %d %d", i, i=20, i);
disply the following menu 1.Disply 2.Copy 3.Append; as per the menu do the file operations 4.Exit
Given a valid 24 hour format time find the combination of the value and write a program ,do not hard the value and if any other inputs provided should work with the logic implemented Input: 11:30 Output: 13:10 Input: 18:25 Output: 21:58
Write a program to replace n bits from the position p of the bit representation of an inputted character x with the one's complement. Method invertBit takes 3 parameters x as input character, p as position and n as the number of positions from p. Replace n bits from pth position in 8 bit character x. Then return the characters by inverting the bits.
Differentiate between a structure and a union.
how to build a exercise findig min number of e heap with list imlemented?
Tell us two differences between new () and malloc ()?
What are the advantages of c preprocessor?
What is the use of function overloading in C?
Explain how can I write functions that take a variable number of arguments?
What is use of #include in c?
What is zero based addressing?
How can I find out how much free space is available on disk?
What are formal parameters?