# C PROGRAMS
C Quiz
➤ Identifiers & Data Types Quiz
➤ Octal Decimal & Hexadecimal
➤ Increment-Decrement Quiz
➤ Relational-Logical Quiz
➤ Arithmetic -Assignment Quiz
➤ Comma Operator Quiz
➤ Sizeof operator Quiz
➤ printf() Quiz Set-1
➤ printf() Quiz Set-2
➤ printf() Quiz Set-3
➤ printf() Quiz Set-4
➤ If statement Quiz in C
➤ If-else statement Quiz
Switch-Case MCQ in C-1 | The switch case statement in C programming is a multi-way decision that tests whether an expression matches one of a number of constant integer values, and branches accordingly. Two keywords are used in the program:- switch and case.
If you are finding any difficulties to answer these SWITCH-CASE statement MCQ in C language then it is recommended to learn these:-
Here, the SWITCH-CASE statement MCQ in C is divided into 2 posts. This post contains 11 questions, and another post SWITCH-CASE statement MCQ in C Part-2 contains 12 program questions on SWITCH-CASE. By solving these problems you can increase your knowledge of switch-case statements.
Q1) Within a switch statement?
a) Continue can be used but Break cannot be used
b) Continue cannot be used but Break can be used
c) Both Continue and Break can be used
d) Neither Continue nor Break can be used
View Answer
Answer:- b) Continue cannot be used but Break can be usedQ2) Which is the alternative to SWITCH in C language?
a) If
b) Else
c) If-Else
d) All of these
View Answer
Answer:- d) All of theseWe can implement a SWITCH statement using IF, ELSE, and ELSE IF control statements.
Q3) In the switch case block which keyword is used to cover unhandled possibilities?
a) break
b) default
c) continue
d) all
View Answer
Answer:- b) defaultIn switch case block, if any case is not matched with the given value then the default statement will be executed.
Q4) In the SWITCH-CASE statement the default case must be used?
a) TRUE
b) FALSE
View Answer
Answer:- b) FALSEThe use of default case in the SWITCH-CASE statement is optional.
Q5) What will be the output of the given C program?
#include<stdio.h>
int main()
{
int a = 2;
switch(a)
{
case 1:
printf("Welcome");
break;
case 2:
printf("Know Program");
break;
default:
printf("Hello");
break;
}
return 0;
}
a) Welcome
b) Know Program
c) Hello
d) Compile-time error
View Answer
Answer:- b) Know ProgramThe value of variable a = 2, hence the case for value 2 will be executed.
Q6) Find the output of the given C switch case program?
#include<stdio.h>
int main()
{
int a = 5;
switch(a)
{
case 1:
printf("Welcome");
break;
case 2:
printf("Know Program");
break;
default:
printf("Hello");
break;
}
return 0;
}
a) Welcome
b) Know Program
c) Hello
d) Compile-time error
View Answer
Answer:- c) HelloThere is no any case for the value a = 5, therefore the default case will be executed.
Q7) What is the output of the given below program?
#include<stdio.h>
int main()
{
int a = 1;
switch(a)
{
case 1:
printf("X");
case 2:
printf("Y");
default:
printf("Z");
break;
}
return 0;
}
a) X
b) XYZ
c) XZ
d) Compile-time error
View Answer
Answer:- b) XYZThe value of a = 1 hence case 1 will be executed but this case statement doesn’t contain break; hence remaining all statements also will be executed.
Q8) Find the output of the below program?
#include<stdio.h>
int main()
{
int a = 2;
switch(a)
{
}
printf("Know Program");
}
a) No Output
b) Know Program
c) Compile-time error
d) None of these
View Answer
Answer:- b) Know ProgramThe switch block may or may not contain any statement.
Q9) What is the output of the given below program?
#include<stdio.h>
int main()
{
int a;
switch(a)
{
printf("Hello");
}
printf("Know Program");
}
a) Know Program
b) Hello
c) Compile-time error
d) None of these
View Answer
Answer:- a) Know ProgramThe switch block didn’t contain any case statement hence the case statement didn’t match with value “a”.
Q10) Find the output of the below program?
#include<stdio.h>
int main()
{
int a = 3;
switch(a)
{
case 1:
printf("X");
break;
case 2:
printf("Y");
break;
default:
printf("Z");
break;
}
printf("L");
}
a) Z
b) ZL
c) L
d) None of these
View Answer
Answer:- b) ZLThe value a=3 matched with case 3 hence it will be executed. The case 3 contains a break therefore control will come out of the switch block. Remaining code of the main() method will be executed. Hence we get output:- ZL.
Q11) What is the output of the given below program?
#include<stdio.h>
int main()
{
int a = 50;
switch(a)
{
case a < 50:
printf("X");
break;
case a >= 50:
printf("Y");
break;
default:
printf("Z");
break;
}
printf("L");
}
a) X
b) Y
c) Z
d) L
e) Compile-time error
View Answer
Answer:- e) Compile-time errorIn case lebel, we must use integer constant. Here, a < 50, a >= 50 are not valid integer constants hence we get a compile time error.
If you enjoyed this post, share it with your friends. Do you want to share more information about the topic discussed above or do you find anything incorrect? Let us know in the comments. Thank you!