Course Content
History of C Language
0/2
Basic Structure of C Program
0/1
Types of Errors
0/1
Language Fundamentals
0/1
Data Types and Modifiers
0/1
Programming with C Language
About Lesson

Switch…case
it is used when we want to check assignment of different values to a single variable and execute corresponding code.

//example program switch...case
#include<stdio.h>

void main()
{
       int x;

        printf("Enter any number for 2,4,6 or 8 :");
        scanf("%d",&x);

       switch(x)
       {
               case 2: printf("TWO"); break;
               case 4: printf("FOUR"); break;
               case 6: printf("SIX"); break;
               case 8: printf("EIGHT"); break;
              default: printf("Invalid Input");
         }

        printf("\nRest of code in main");

}

sometimes it works as alternative to multiple if.

break transfers the program control to outside of the current block.

You cannot copy content of this page