Welcome Guest | Sign in | Register

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

01. What is the output of following program?
void main(){
int a=2;
switch(a);
{
case 1: printf("A");
case 2: printf("B");
case 3: printf("C");
break;
case 4: printf("D");
default: printf("E");
break;
}
}  
A. A B C B. A B C E
C. A B C D E D. error

Answer and Explanation

Answer: error

Explanation:
switch(a);
terminated by ; 

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
02. What is the output of following program?

void main(){
int a=2;
switch(a);
{
case 1: printf("A");
case 2: printf("B");
case 3: printf("C");
break;
case 4: printf("D");
default : printf("E");
break;
}
}
A. B C B. B D
C. B E D. error

Answer and Explanation

Answer: B E

Explanation:
There is no explanation...

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
03. What is the output of following program?
void main(){
int a=2;
switch(a)
{
case 1: printf("A");
break;
case 2: printf("B");
continue;
case 3: printf("C");
break;
case 4; printf("D");
default: printf("E");
}
}
A. B E B. B C E
C. B C D E D. error

Answer and Explanation

Answer: error

Explanation:
There is no explanation...

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
04. What is the output of following program?

void main(){
int a=2;
switch(a)
{
case4: printf("A");
break;
case3: printf("B");
case2: printf("C");
case1: printf("D");
break;
default: printf("E");
}
}
A. C B. D
C. CD D. E

Answer and Explanation

Answer: E

Explanation:
answer E, because no space with case.    

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
05. What is the output of following program?

void main(){
int a=2;
switch(a)
{
case 4: printf("A");
break;
case 3: printf("B");
case default : printf("C");
case 1 : printf("D");
break;
case 5 : printf("E");
}
}
A. C B. CD
C. E D. error

Answer and Explanation

Answer: error

Explanation:
error

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
06. What is the output of following program?

void main(){
int a=2;
switch(a)
{
case 4: printf("A");
break;
case 3: printf("B");
case default : printf("C");
case 1 : printf("D");
break;
case 5 : printf("E");
}
}
A. A B C B. A B C E
C. A B C D E D. error

Answer and Explanation

Answer: error

Explanation:
switch(a);
terminated by ;

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
07. What will be output when you will execute following c code? 
 
#include
int main(){
int const X=0;
switch(5/4/3){
case X: printf("Clinton");
break;
case X+1:printf("Gandhi");
break;
case X+2:printf("Gates");
break;
default: printf("Brown");
}
return 0;
}
Choose all that apply: 
A. Clinton B. Gandhi
C. Gates D. Brown
E. Compilation error

Answer and Explanation

Answer: Compilation error

Explanation:
Case expression cannot be constant variable.

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
08. 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.

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
09. What will be output when you will execute following c code?
01 #include
02 int main()
03 {
04 int check=2;
05 switch(check){
06 case 1: printf("D.W.Steyn");
07 case 2: printf(" M.G.Johnson");
08 case 3: printf(" Mohammad Asif");
09 default: printf(" M.Muralidaran");
10 }
11
12 return 0;
13
14 }
Choose all that apply:
A. M.G.Johnson B. M.Muralidaran
C. M.G.Johnson Mohammad Asif M.Muralidaran D. Compilation error
E. None of the above

Answer and Explanation

Answer: M.G.Johnson Mohammad Asif M.Muralidaran

Explanation:
There is no explanation...

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
10. What will be output when you will execute following c code?

#include
void main(){
int const X=0;
switch(5/4/3){
case X: printf("Clinton");
break;
case X+1:printf("Gandhi");
break;
case X+2:printf("Gates");
break;
default: printf("run time error");
}
}
A. Clinton B. Gandhi
C. Gates D. Compilation error

Answer and Explanation

Answer: Compilation error

Explanation:
There is no explanation...

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
11. What will be output when you will execute following c code? 

#include
void main(){
switch(5||2|1){
case 3&2:printf("Anatomy of a Murder");
break;
case -~11:printf("Planet of Apes");
break;
case 6-3<<2:printf("The conversation");
break;
case 5>=5:printf("Shaun of the Dead");
}
}
A. Anatomy of Murder B. Planet of Apes
C. The conversation D. Compilation error

Answer and Explanation

Answer: Compilation error

Explanation:
There is no explanation...

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
12. What will the output of the sample code above below? 

Code:
int i = 4;
switch (i)
{
default:
;
case 3:
i += 5;
if ( i == 8)
{
i++;
if (i == 9) break;
i *= 2;
}
i -= 4;
break;
case 8:
i += 5;
break;
}
printf("i = %d\n", i);
A. i = 5 B. i = 8
C. i = 9 D. i = 10
E. i = 18

Answer and Explanation

Answer: i = 5

Explanation:
There is no explanation...

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum



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