Posts

Switch Statement in C

Image
The switch statement in C is an alternate to if-else-if ladder statement which allows us to execute multiple operations for the different possibles values of a single variable called switch variable. Here, We can define various statements in the multiple cases for the different values of a single variable. The syntax of switch statement in c language is given below: switch (expression){     case  value1:       //code to be executed;        break ;   //optional    case  value2:       //code to be executed;        break ;   //optional    ......          default :       code to be executed  if  all cases are not matched;     }  ...

if else statement for C

Image
The if-else statement in C is used to perform the operations based on some specific condition. The operations specified in if block are executed if and only if the given condition is true. There are the following variants of if statement in C language. If statement If-else statement If else-if ladder Nested if If Statement The if statement is used to check some given condition and perform some operations depending upon the correctness of that condition. It is mostly used in the scenario where we need to perform the different operations for the different conditions. The syntax of the if statement is given below. if (expression){   //code to be executed    }   Flowchart of if statement in C Let's see a simple example of C language if statement. #include<stdio.h>      int  main(){     int  number=0;     printf( "Enter a...