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
Answers were Sorted based on User's Feedback
Answer / naksh @tcs
Answer is 6;
Sum being the static variale will retain its value state
between he function calls.
| Is This Answer Correct ? | 17 Yes | 2 No |
Answer / 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 |
program to find the second largest word in a paragraph amongst all words that repeat more thn twice
Why C language is a procedural language?
what is the associativity of bitwise OR operator?
Process by which one bit pattern in to another by bit wise operation is?
Differentiate between functions getch() and getche().
without using control structures and control structures find the max and min of given 2 nos
Describe newline escape sequence with a sample program?
Why is c still so popular?
Draw a flowchart to produce a printed list of all the students over the age of 20 in a class .The input records contains the name and age of students. Assume a sentinel value of 99 for the age field of the trailer record
what do the 'c' and 'v' in argc and argv stand for?
Explain how many levels deep can include files be nested?
Explain zero based addressing.