If-else” and also “switch” room conditional statements. The crucial difference is that switch despatches immediately to the case concerned, commonly via an indexing jump, rather than having actually to evaluate every the problems that would certainly be forced in an if-elsechain, which way that code at the finish of the chain is reached much more slowly than code in ~ the beginning.

*
*
*

if-else example

#include void main() int no; printf("Enter the number:"); scanf("%d", &no); if(no%2==0) printf("the number is even ); rather printf("the number is odd");

Switch case

The move statement is a multi-way decisionIt tests whether an expression matches any one of the constant values orThe general kind of switch-case is as below,switch(expression) situation const-expr 1: statement 1; break; situation const-expr 2: statement 2; break; case const-expr 3: statement 3; break; default: statementsexpression in switch have to be an integer or personality expression. Float or any type of other data kind is notEach situation is labeled by one or an ext integer-valuedIf a instance matches the expression value then execution starts in ~ thatValue the all instance expressions must beIf nobody of the situations are matched climate the default situation is executed.switch (grade) instance 1: printf("Fall (F) "); break; case 2: printf("Bad (D) "); break; case 3: printf("Good (C) "); break; situation 4: printf("Very an excellent (B) "); break; situation 5: printf("Excellent (A) "); break; default: printf("You have inputted alse grade ") break;Rules because that switch statementThe move expression must be one integral type. To rise or various other data species are notCase labels need to be constant or constantCase labels should be unique.Case labels must end withThe break statement is optional.The default case statement is optionalNesting of a switch statement is allowed