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 |
What is structure packing ?
what is void pointer?
Table of Sudoku n*n
What are terms in math?
How can a number be converted to a string?
how to reverse string "Hello World" by using pointers only. Without any temp var
A marketing company wishes to construct a decision table to decide how to treat clients according to three characteristics: Gender, City Dweller, and age group: A (under 30), B (between 30 and 60), C (over 60). The company has four products (W, X, Y and Z) to test market. Product W will appeal to female city dwellers. Product X will appeal to young females. Product Y will appeal to Male middle aged shoppers who do not live in cities. Product Z will appeal to all but older females.
What is the role of this pointer?
What does int main () mean?
how does a general function , that accepts an array as a parameter, "knows" the size of the array ? How should it define it parameters list ?
How many types of sorting are there in c?
i need all types of question paper releted to "c" and other language.