Table of Contents
C Decision Making Statement
As the name says decision making statements helps us to take decision based on certain condition. In C programming we have following decision making statements.
- if statement
- if-else statement
- else-if statement
- nested if-else statement
- switch statement
if statement

This is the most simple and easy decision making statement in C program. In this, if statement will check for certain condition and if the condition is true then it will execute block of code written in it. If the condition is false then it will not execute block of code.
Like while loop if block also accepts boolean value which means if we enter 0 as condition then it will be considered as false and non-zero value will be considered as true.
Syntax:
if(condition)
{
statements;
}
Example:
int i = 2;
if(i<5)
{
printf("Value of i is less than 5");
}
Output:
Value of i is less than 5
if-else statement

In this is we have two separate blocks of code and one of them get executed based of certain condition. We have if block and else two separate blocks, if block check the condition and if the condition is true then if block will get executed and if the condition is false then else block will get executed.
In simple word there are two separate blocks of code and which block will get executed is depend on condition mention in if’s parameter.
In below example we have set value of i variable to 12, next in if parameter we are checking if value of i is less than 5, now we can see that condition is false, hence else block will get executed instead of if block.
Like while loop if block also accepts boolean value which means if we enter 0 as condition then it will be considered as false and non-zero value will be considered as true.
Syntax:
if(condition)
{
statements;
}
else
{
statements;
}
Example:
int i = 12;
if(i<5)
{
printf("Value of i is less than 5");
}
else
{
printf("Value of i is greater than 5");
}
Output:
Value of i is greater than 5
else-if statement

We use else-if block for multipath decision making.
In this is we have many separate blocks of code and one of them get executed based of certain condition. We have three block starting with if block, else if block and else block. First if block will check if mention condition is true or not, if the condition is true then if block will get executed and if the condition is false then pointer shifts to very next else if block.
else if block will check for its condition, if the condition is true then else if block will get executed and if the condition is false then pointer shifts to very next else if block.
And this goes on until one condition get satisfied or last block i.e. else block will get executed.
In simple words if block and else if blocks will check for certain condition one by one and who ever’s condition get satisfied first then respective block is executed, and if no condition is satisfied then last block i.e. else block will get executed.
There is no limit on count of else if block we can have as many as we want.
We cannot use else if block and else block without if block.
Like while loop if block and else if block also accepts boolean value which means if we enter 0 as condition then it will be considered as false and non-zero value will be considered as true.
Syntax:
if(condition)
{
statements;
}
else if(condition)
{
statements;
}
else if(condition)
{
statements;
}
else if(condition)
{
statements;
}
.
.
.
else
{
statements;
}
Example:
int i = 3;
if(i==1)
{
printf("Value of i is equal to 1");
}
else if(i==2)
{
printf("Value of i is equal to 2");
}
else if(i==3)
{
printf("Value of i is equal to 3");
}
else if(i==4)
{
printf("Value of i is equal to 4");
}
else
{
printf("Value of i is not 1, 2, 3 or 4");
}
Output:
Value of i is equal to 3
Try this fun quiz
CHECKOUT OTHER RELATED TOPICS
CHECKOUT OTHER QUIZZES
Quizzes on Operator |
Easy Quiz on Operators in C part 1 |
Easy quiz on operators in C part 2 |
Easy quiz on operators in C part 3 |
Quizzes on Loops |
Easy quiz on loops in C part 1 |
Easy quiz on loops in C part 2 |
Easy quiz on loops in C part 3 |
Quizzes on Decision Making Statement |
Easy Quiz On Decision Making Statements Part 1 |
Easy Quiz On Decision Making Statements Part 2 |
Quizzes on String |
Easy quiz on String in C programming part 1 |
Quizzes on Array |
Easy quiz on Array in C programming – part 1 |
5 – Best Java program to convert decimal to binary |
New Quizzes Coming soon.. |
PRACTICALS IN C PROGRAM
Programs to understand the basic data types and I/O.
Programs on Operators and Expressions.
Programs on decision statements.
Programs on looping.
Programs to understand the basic data types and I/O.
Programs on arrays.
Programs on functions.
Programs on structures and unions.
Programs on pointers.
Programs on string manipulations.
