0% found this document useful (0 votes)
437 views

Switch Statement 1

The document contains 29 questions about the output of various C code snippets using switch statements. Most involve different conditions, data types, fall-through behavior, and order of operations within switch blocks. The questions test understanding of how switch statements work in C under different scenarios.

Uploaded by

Fake Acc
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
437 views

Switch Statement 1

The document contains 29 questions about the output of various C code snippets using switch statements. Most involve different conditions, data types, fall-through behavior, and order of operations within switch blocks. The questions test understanding of how switch statements work in C under different scenarios.

Uploaded by

Fake Acc
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Q1.What is the output of this C code?

#include <stdio.h>
int main()
{
int a = 1, b = 1;
switch (a) yes no
{
case a*b:
printf("yes ");
case a-b:
printf("no\n");
break;
}
}

Q2.
What is the output of this C code?
#include <stdio.h>
int main()
{
int x = 97; no
switch (x)
{
case 'a':
printf("yes ");
break;
case 97:
printf("no\n");
break;
}
}

Q3.
What is the output of this C code?

#include <stdio.h>
int main()
{
float f = 1;
switch (f)
{
case 1.0: yes
printf("yes\n");
break;
default:
printf("default\n");
}
}
Q4.
#include <stdio.h>
void main()
{
double ch;
printf("enter a value btw 1 to 2:");
scanf("%lf", &ch);
switch (ch)
{
if 1 entered 1
if 2 entered 2
case 1:
printf("1");
break;
case 2:
printf("2");
break;
}
}

Q5.
What is the output of this C code(When 1 is entered)?

#include <stdio.h>
void main()
{
int ch;
printf("enter a value btw 1 to 2:");
scanf("%d", &ch);
switch (ch)
{
case 1:
printf("1\n");
default:
printf("2\n");
}
}
Q6.
What is the output of this C code(When 2 is entered)?

#include <stdio.h>
void main()
{
int ch;
printf("enter a value btw 1 to 2:");
scanf("%d", &ch);
switch (ch) 2
{
case 1:
printf("1\n");
break;
printf("hi");
default:
printf("2\n");
}
}
Q7.
What is the output of this C code(When 1 is entered)?

#include <stdio.h>
void main()
{
int ch;
printf("enter a value btw 1 to 2:");
scanf("%d", &ch);
switch (ch, ch + 1)
{
case 1:
2
printf("1\n");
break;
case 2:
printf("2");
break;
}
}
Q8.
What is the output of this C code?

#include <stdio.h>
int main()
{
switch (printf("Do"))
{
case 1: dosecond
printf("First\n");
break;
case 2:
printf("Second\n");
break;
default:
printf("Default\n");
break;
}
}
Q9.
Comment on the output of this C code?

#include <stdio.h>
int main()
{
int a = 1;
switch (a)
case 1:
printf("%d", a); 1111
case 2:
printf("%d", a);
case 3:
printf("%d", a);
default:
printf("%d", a);
}
Q10.
#include<stdio.h>
int main()
{
default block executed
switch(2/3)
{
case 1:
printf("case 1 executed ");

case 2:
printf("case 2 execcuted ");
break;
default:
printf("Default block executed");
}
return 0;
}

Q11.
#include<stdio.h>
int main()
{
int i = 1;
switch(i)
{
case i:
printf("case 1 executed");
break;
case i + 1;
printf("case 2 executed");
break;
default:
printf("default block executed");
break;
}
return 0;
}

Q12.
#include<stdio.h>

int main()
{
char ch = 65;
switch(ch)
{
case 'A':
printf("Apple");
break;
case 'B':
printf("Bing");
break;
default:
printf("Bye");
break;
}
return 0;
}

Q13.
#include<stdio.h>
int main()
{
int i = 65;

switch(i)
{
case 65:
printf("Integer 65");
break;
case 'A':
printf("Char 65");
break;
default:
printf("Bye");
}
return 0;
}

Q14.
#include<stdio.h>
int main()
{
int i = 65;
char ch = 'B';
switch(ch, i)
{
case 65:
printf("Integer");
break;
case 'B':
printf("Char");
break;
default:
printf("Bye");
}
return 0;
}

Q15.
#include<stdio.h>
int main()
{
int i = 1;
i++;
switch(i--)
{
case 1:
printf("case 1 executed");
break;
case 2:
printf("case 2 executed");
break;
default:
printf("default block executed");
break;

}
return 0;
}

Q16.
#include<stdio.h>
int main(){
int num = 5;
switch(num++ == 5)
{
case 1:
printf("TRUE");
break;
case 0:
printf("FALSE");
break;
default:
printf("inside default");
}
return 0;
}

Q17.
#include<stdio.h>
int main(){
switch(1)
{
case 1:
printf("inside case 1 ");
break;
printf("Hai");
default:
printf("inside default");
break;
}
return 0;
}
Q18.
#include<stdio.h>
int main(){
char ch = 96.0;
switch(ch)
{
case 96:
printf("inside case");
break;
default:
printf("inside default");
}
return 0;
}

Q19.
#include<stdio.h>
int main(){
int i = 3, j = 4;
switch(i | j)
{
case 1:
printf("inside case 1");
break;
case 3:
printf("inside case 3");
break;
case 4:
printf("inside case 4");
break;
case 7:
printf("inside case 7");
break;
}
return 0;
}

Q20.
#include<stdio.h>
int main(){
int n = 4;
switch(n)
{
default:
printf("Hai default ");
case 1:
printf("Hai case 1 ");
case 2:
printf("Hai case 2 ");
case 3:
printf("Hai case 3 ");
}
return 0;
}

Q21.
What will be output when you will execute following c code?
#include<stdio.h>
void main(){
int movie=1;
switch(movie<<2+movie){
default:printf("hey bhagwan");
case 4: printf(" bachale");
case 5: printf(" C programming ");
case 8: printf(" Se");
}
}

Q22.
What will be output when you will execute following c code?
#include<stdio.h>

void main(){
auto money=10;
switch(money,money*2){
case 10: printf("pankaj");
break;
case 10*2:printf("Sharma");
break;
case 10*3:printf("is");
break;
default: printf("Worst");
case 10*4:printf("Faculty");
break;
}
}

Q23.
What will be output when you will execute following c code?
#include<stdio.h>
void main(){
switch(5||2|1){
case 3&2:printf("Pankaj Sharma");
break;
case -~11:printf("GLA");
break;
case 6-3<<2:printf("CSE");
break;
case 5>=5:printf("First year");
}
}

Q24.
What will be output when you will execute following c code?

#include<stdio.h>
void main(){
unsigned char c=280;
switch(c){
printf("pankaj");
case 280:printf("Sharma");
case 24: printf("CSE");
default: printf("First");
printf("Year");
}

Q25.
What will be output when you will execute following c code?

#include<stdio.h>
void main(){
int a=5;
a=a>=4;
switch(2){
case 0:int a=8;
case 1:int a=10;
case 2:++a;
case 3:printf("%d",a); 2
}
}

Q26.
What will be output when you will execute following c code?

#include<stdio.h>
void main(){
int a=3,b=2;
a=a==b==0;
switch(1){
a=a+10;
} 1
sizeof(a++);
printf("%d",a);
}

Q27.
#include <stdio.h>
int main() {
int i = 3;

switch(i){
case 0 :
printf("DOT BALL");
break;
case 1 :
printf("SINGLE");
break;
case 2 :
printf("DOUBLE");
break;
case 3 :
printf("TRIPLE");
break;
}
}

Q28.

#include <stdio.h>
int main()
{
int num = 2;
switch (num + 2)
{
case 1:
printf("Case 1: ");
case 2:
printf("Case 2: ");
case 3:
printf("Case 3: ");
default:
printf("Default: ");
}
return 0;
}

Q29.

You might also like