Switch Statement in C
Here are the example of Switch Statement in C language:
#include <stdio.h>
int main()
{
int day = 2;
switch (day) {
case 1:
printf("Monday");
break;
case 2:
printf("Tuesday");
break;
case 3:
printf("Wednesday");
break;
case 4:
printf("Thrusday");
break;
case 5:
printf("Friday");
break;
case 6:
printf("Saturday");
break;
case 7:
printf("Sunday");
break;
default:
printf("Not a valid number");
}
return 0;
}
Output
Tuesday
Switch statement in Programming
Switch statement in programming enables the execution of different code blocks based on the value of an expression, providing a structured approach to handle multiple cases efficiently. It enhances code readability and simplifies decision-making processes, making it a valuable tool for managing program flow and facilitating branching logic in software development.
Table of Content
- What is Switch Statement?
- Syntax and Structure of Switch Statement
- Case Statement
- Break Statement
- Default Statement
- Switch Statement in C
- Switch Statement in C++
- Switch Statement in Java
- Switch Statement in Python
- Switch Statement in C#
- Switch Statement in JavaScript
Contact Us