Welcome Guest | Sign in | Register
Switch-case - Discussion Page For Q.10626 | C Programming Questions and Answers | C Programming Free Online-Tests | LucentBlackBoard | LucentBlackBoard.com

Home > Java Programming > Switch-case > Questions and Answers

Q: What would be the output if option = 'H'?
switch(option)
{
case 'H' : printf("Hello");
case 'W' : printf("Welcome");
case 'B' : printf("Bye");
break;
}
A. Hello B. Hello Welcome
C. Hello Welcome Bye D. None of the above

Answer and Explanation

Answer:Hello Welcome Bye

Explanation:
If option = H then the first case is true so "Hello" gets printed but there is no break statement after this case to come out of the switch statement so the program execute all other case statements also and Hello Welcome Bye get printed.

Comment on this Question

Name:

Loading...




Partner Sites
LucentBlackBoard.com                  SoftLucent.com                  LucentJobs.com
All rights reserved © 2012-2015 SoftLucent.