Switch Case in C language | part 8 = total programming

                                                            Switch Case in C language

SWITCH CASE =

  DEFINITION = Switch Case is a statement in C language. The switch statement in C tests the value of a variable and compares it with multiple cases. Once the case match is found a block of statements associated with that particular case is executed.

    SYNTAX = The general syntax for Switch Case is as follows =

                                     switch( expression )

{
	case value-1:
			Block-1;
			Break;
	case value-2:
			Block-2;
			Break;
	case value-n:
			Block-n;
			Break;
	default:
			Block-1;
			Break;
}
Statement-x; 

 KEYWORDS IN SWITCH CASE = switch, case, break, and default.


FLOWCHART OF SWITCH CASE =



Example =

#include <conio.h>
#include <stdio.h>
void main()
{
   int x = 2;
   switch (x)
   {
       case 1: printf("Choice is 1");
               break;
       case 2: printf("Choice is 2");
                break;
       case 3: printf("Choice is 3");
               break;
       default: printf("Choice other than 1, 2 and 3");
                break
   }

}

No comments:

Post a Comment

Break and Continue in C language | part 9 =total programming

                           C break and continue Hello Guys, in this post I am going to show you C Break and Continue, So, Let get started = ...