GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Placement Papers  >  TCS  >  C
Go To First  |  Previous Question  |  Next Question 
 C  |  Question 73 of 87    Print  
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

A. 6
B. 8
C. 1
D. 3


  
Total Answers and Comments: 4 Last Update: June 04, 2008   
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
June 08, 2006 12:54:59   #1  
venkatakrishnan        

RE: Consider the following C codemain(){
the answer is 6 as the sum is declared as static the value does not change
 
Is this answer useful? Yes | No
July 06, 2006 05:32:33   #2  
Vikas Gupta        

RE: Consider the following C codemain(){
the answer would be 3.Because Everytime the function is call the sum is initialised to 0 and hence the answer would be 3.
 
Is this answer useful? Yes | No
July 06, 2006 05:35:58   #3  
Vikas Gupta        

RE: Consider the following C codemain(){
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().:)
 
Is this answer useful? Yes | No
June 04, 2008 14:59:34   #4  
anu1985 Member Since: May 2008   Contribution: 11    

RE: 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
the answer will 6
 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape