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

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

Q: What will be output when you will execute following c code? 
 
#include
enum actor{
SeanPenn=5,
AlPacino=-2,
GaryOldman,
EdNorton
};
int main(){
enum actor a=0;
switch(a){
case SeanPenn: printf("Kevin Spacey");
break;
case AlPacino: printf("Paul Giamatti");
break;
case GaryOldman:printf("Donald Shuterland");
break;
case EdNorton: printf("Johnny Depp");
}
return 0;
}
Choose all that apply:  
A. Kevin Spacey B. Paul Giamatti
C. Donald Shuterland D. Johnny Depp
E. Compilation error

Answer and Explanation

Answer:Johnny Depp

Explanation:
Default value of enum constant GaryOldman = -2 +1 = -1 And default value of enum constant EdNorton = -1 + 1 = 0 Note: Case expression can be enum constant.

Comment on this Question

Name:

Loading...




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