Default keyword in Switch case in C by R4R Team

In switch case statement, default are the optional part.
-default part is execute when no case is match with required value.

Syntax-
switch(variable)
{
case value1:
body
case value2:
body
.
.
.
.
.
default:
body
}


program-

#include< stdio.h>
int main()
{
int a;
printf("Enter Number\n");
scanf("%d",&a);
switch(a)
{
case 1:
printf("case 1 is execute\n");
case 2:
printf("case 2 is execute\n");
default:
printf("default part is execute");
}
}


output-

Enter Number
5
default part is execute

-In this program, we take an input of the integer number and pass in switch statement
-In output, we give a value 5, which is not match any case in the program then it execute the default part of the switch so that output is "default part is execute"




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!