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



consider the following C code main() { int i=3,x; while(i>0) { x=fu..

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

consider the following C code main() { int i=3,x; while(i>0) { x=fu..

Answer / yogendra jain

6

Is This Answer Correct ?    15 Yes 2 No

consider the following C code main() { int i=3,x; while(i>0) { x=fu..

Answer / vignesh1988i

the final value of x is 6

Is This Answer Correct ?    10 Yes 1 No

consider the following C code main() { int i=3,x; while(i>0) { x=fu..

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

Post New Answer

More C Interview Questions

What is structure packing ?

2 Answers   HP,


what is void pointer?

2 Answers  


Table of Sudoku n*n

0 Answers  


What are terms in math?

0 Answers  


How can a number be converted to a string?

1 Answers  






how to reverse string "Hello World" by using pointers only. Without any temp var

1 Answers  


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.

2 Answers  


What is the role of this pointer?

0 Answers  


What does int main () mean?

0 Answers  


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 ?

0 Answers  


How many types of sorting are there in c?

0 Answers  


i need all types of question paper releted to "c" and other language.

0 Answers  


Categories