Friends here is five C-questions involving Switch Case.
Lets solve these......
Q.1
What will be output when you will execute following c code?
#include<stdio.h>
void main(){
int check=2;
switch(check){
case 1: printf("D.W.Steyn");
case 2: printf(" M.G.Johnson");
case 3: printf(" Mohammad Asif");
default: printf(" M.Muralidaran");
}
}
Q.2
What will be output when you will execute following c code?
#include <stdio.h>
#define L 10
void main(){
auto money=10;
switch(money,money*2){
case L: printf("Willian");
break;
case L*2:printf("Warren");
break;
case L*3:printf("Carlos");
break;
default: printf("Lawrence");
case L*4:printf("Inqvar");
break;
}
}
Q.3
What will be output when you will execute following c code?
#include <stdio.h>
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("Brown");
}
}
Q.4
What will be output when you will execute following c code?
#include <stdio.h>
enum actor{
SeanPenn=5,
AlPacino=-2,
GaryOldman,
EdNorton
};
void 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");
}
}
Q.5
What will be output when you will execute following c code?
#include <stdio.h>
void main(){
switch(*(1+"AB" "CD"+1)){
case 'A':printf("Pulp Fiction");
break;
case 'B':printf("12 Angry Man");
break;
case 'C':printf("Casabance");
break;
case 'D':printf("Blood Diamond");
}
}
Lets solve these......
Q.1
What will be output when you will execute following c code?
#include<stdio.h>
void main(){
int check=2;
switch(check){
case 1: printf("D.W.Steyn");
case 2: printf(" M.G.Johnson");
case 3: printf(" Mohammad Asif");
default: printf(" M.Muralidaran");
}
}
Q.2
What will be output when you will execute following c code?
#include
#define L 10
void main(){
auto money=10;
switch(money,money*2){
case L: printf("Willian");
break;
case L*2:printf("Warren");
break;
case L*3:printf("Carlos");
break;
default: printf("Lawrence");
case L*4:printf("Inqvar");
break;
}
}
Q.3
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("Brown");
}
}
Q.4
What will be output when you will execute following c code?
#include
enum actor{
SeanPenn=5,
AlPacino=-2,
GaryOldman,
EdNorton
};
void 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");
}
}
Q.5
What will be output when you will execute following c code?
#include
void main(){
switch(*(1+"AB" "CD"+1)){
case 'A':printf("Pulp Fiction");
break;
case 'B':printf("12 Angry Man");
break;
case 'C':printf("Casabance");
break;
case 'D':printf("Blood Diamond");
}
}