Skip to main content

Posts

Showing posts from May 19, 2020

switch case in c

switch case in c: What is switch case in c ? It is used for checking the equality One switch statement can have multiple case statement. After each case statement break statement is necessary  break statement is used for terminating the control from switch case in c. In switch statement default statement is used for displaying the invalid input. Basic Syntax: scanf("%d",x); switch(x) { case 1: code which will be executed when x=1 break; case 0: code which will be executed when x=0 break; case 10: code which will be executed when x=10 break; default : code if any input is invalid } Explanation: In the above syntax the code in case 1 will be executed if the value of x = 1, if x=0 then case 0 will be executed. So in general any thing written after case is compare with the input given by the user ad if it is equal then the code in that case is executed. Note:  (:) - should be present after every case statement.