- In if statement we observed that the statements present inside if block is executes only when condition is true. It does nothing when the condition is false. if-else statement take care of true as well as false condition.
- if-else statement contains two blocks if block and else block. If condition is true then statements present inside if block gets executed and if condition is false statements present inside the else block gets executed.
- Here is a syntax of if-else statement is as follows:
- If the condition is true then the statements present inside the if block will be executed and if the condition is false then the statements present inside the else block will be executed. You can understand the concept of if-else statement more clearly with the help of following diagram:
- Here is an example of if-else statement as follows:
printf(“n Enter the value of a and b:”);
printf(“value of a and b are equal”);
printf(“value of a and b are not equal”);
The output of the above program is as follows:
value of a and b are not equal