CPC Presentation 12
CPC Presentation 12
Batch :- D
Switch Case
Introducti
on
A control structure in C.
Used to choose one action from multiple options.
Alternative to multiple if-else statements.
Why Use Switch Case?
Simplifies decision-making in programs.
Improves code readability for multiple conditions.
Efficient for scenarios with discrete values.
Syntax of Switch Case
Switch(expression) {
case value1:
// Code block
break;
case value2:
// Code block
break;
default:
// Code block
}
Key elements: switch, case, break, default.
Key Components
Expression:- Must evaluate to an integer or character.