Consider the following C codemain(){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 isa.6b.8c.1d.3

A
This question is related to TCS Interview

Showing Answers 1 - 1 of 1 Answers

Meena Goel

  • Sep 12th, 2007
 

Value of x finally should be 6, because their is a staic variable sum that value should be remain in memory. When the function is to be calling first time then the value of sum will be 3. When it calls second time then the value of sum will be 3+2=5 and after third call the value of sum will be 5+1=6. At last it will return the value of sum to x that is 6.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions