Friday, April 19, 2019

Switch Statement

0 comments

Switch Statement

The switch case statement is used we have more options and to perform a specific operation, each option.
           Syntax: - switch(expression) {
                             Case 1: statement;
                                     Break;
                             Case 2: statement;
                                     Break;
                                         :
                                         :
                             Default: statement;
                                }

Example: -


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <stdio.h>
int main()
{
     int num=2;

     switch(num)
     {

         case 1:
           printf("Case1: Value is: %d", num);

         case 2:

           printf("Case2: Value is: %d", num);

         case 3:
           printf("Case3: Value is: %d", num);

         default:
           printf("Default: Value is: %d", num);
    }

    return 0;
}

No comments:

Post a Comment