SWITCH Statement in C Language

SWITCH Statement in C Language:

(1) SWITCH Statement successively tests the value of an expression against a list of integer or character constants. When a match is found, the statements associated with that constant are executed.

(2) Sample C language code and its output, as shown:

Sample C language code for SWITCH Statement
#include <stdio.h>
#include <conio.h>
int main()
{
  int x;
  x = 2;
switch(x)
  {
    case 1:
        printf(“LOW”);
        break;
    case 2:
        printf(“Medium”);
        break;
    case 3:
        printf(“High”);
        break;
  }
 
  getch();
  return 0;
}

(3) After that go to the “Build” menu and select the “Build” option for publishing the code as shown.

click on build for switch statement in codeblocks

(4) After building the code, press the “Run” button, as shown.

press on run button for switch ststement in c

(5) After pressing the “run” button, the output screen is opened, as shown.

Output obtain from switch statement in C

SWITCH Statement Syntax:

switch(expression) {
  case x:
    // code block
    break;
  case y:
    // code block
    break;
    // code block
}

Use of LEN Function in SQL
Use of CONCAT_WS Function in SQL
Use of CONCAT Function in SQL
Use of UPPER Function in SQL
CONCAT_WS (Transact-SQL)– Microsoft Docs

Leave a Reply