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

This question is related to TCS Interview

Showing Answers 1 - 9 of 9 Answers

venkatakrishnan

  • Jun 8th, 2006
 

the answer is 6 as the sum is declared as static the value does not change

Vikas Gupta

  • Jul 6th, 2006
 

the answer would be 3.Because Everytime the function is call the sum is initialised to 0 and hence the answer would be 3.

  Was this answer useful?  Yes

Vikas Gupta

  • Jul 6th, 2006
 

and for the matter,Please chaeck the question again...you can'nt define a function inside another function in C...and in this question the func appears to be defined inside the function main().:)

  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