Conditional statements in C help you to make a decision based on certain conditions. These conditions are specified by a set of conditional statements having boolean expressions which are evaluated to a boolean value of true or false.
In our life, we frequently encounter certain situations where we have to make a decision be it your favorite food, movie, hobby, or the color of our shoes. In C programming also, you may encounter similar kinds of situations where you need to make a decision based on the two possibilities that are yes/no or true/false acceptance, we will learn all about the conditional statements in this article.
There are the following types of conditional statements in C.
If statement
If-Else statement
- If statement
The single if statement in C language is used to execute the code if a condition is true. It is also called a one-way selection statement. When we use the if condition, we pass the argument and if the argument will be satisfied then the respective code will be executed otherwise nothing can happen.
If-else statement
The if-else statement in C language is used to execute the code if the condition is true or false. It is also called a two-way selection statement.
The single if statement may work pretty well, but if you want to work with multiple variables or the extended conditional parameters, then the if-else statement is the optimum choice. By using the if statement, only one block of the code executes after the condition is true but by using the if-else statement, there are two possible blocks of code where the first block is used for handling the success part and the other one for the failure condition.