GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Placement Papers  >  TCS  >  C
Go To First  |  Previous Question  |  Next Question 
 C  |  Question 69 of 87    Print  
Consider the following program segment
int n, sum=1;
switch(n)
{
case 2:sum=sum+2;
case 3:sum*=2;
break;
default: sum=0;
}
If n=2, what is the value of sum

A. 0
B. 6
C. 3
D. None of these


  
Total Answers and Comments: 4 Last Update: October 17, 2006   
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
January 03, 2006 13:59:52   
       

c

c is the correct answer


 
Is this answer useful? Yes | No
February 23, 2006 09:56:08   
Rohan Member Since: November 2005   Contribution: 11    

RE: Consider the following program segmentint n, ...

Ans is ( B )

sum 6 reason is

case 2 : sum sum+2 //sum 1+2 sum 3 and no break so

case 3 : sum* 2 //sum 3*2 sum 6

break;

sum 6 is the answer


 
Is this answer useful? Yes | No
June 08, 2006 13:17:57   
venkatakrishnan        

RE: Consider the following program segmentint n, ...
the answer is 0 not either 3 or 6
 
Is this answer useful? Yes | No
October 17, 2006 06:04:28   
SreeAravind        

RE: Consider the following program segmentint n, ...

Hi Some of them wrote wrong answers

its answer is B:6

Because there is no break statement in case 2 so it further exec case 3 also...


 
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 - 2010 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape