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

Switch Case

Uploaded by

Arman Danesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Switch Case

Uploaded by

Arman Danesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Switch Statement

Instead of writing many if..else statements, you can use the switch
statement.

The switch statement selects one of many code blocks to be executed:


switch (expression)
{
case value1:
code to be executed if expression=value1;
break;
case value2:
code to be executed if expression=value2;
break;

default:
code to be executed if expression is different

from all values;

}
switch(expression) {

case constant-expression :
statement(s);
break; /* optional */

case constant-expression :
statement(s);
break; /* optional */

/* you can have any number of case


statements */
default : /* Optional */
statement(s);
}
● If we do not use the break statement, all statements after the matching label are

also executed.
● The default clause inside the switch statement is optional.
Write a C program to find maximum
between two numbers using switch case
Write a C program to check even or odd
number using switch case
Write a C program to check positive negative
or zero using switch case

You might also like