If Statement in C Programming
If Statement in C Programming
Introduction to If Statement
The if statement in C programming is used to make decisions in a program. It allows the program to execute a block of code only when a specific condition is true.
The if statement is one of the most important control statements in C programming.
Syntax of If Statement
// code to execute if condition is true
}
Example of If Statement
int main() {
int age = 20;
if(age >= 18) {
printf(“You are eligible to vote”);
}
return 0;
}
How If Statement Works
- The condition is checked
- If the condition is true (1), the code inside the block executes
- If the condition is false (0), the block is skipped
Using If Statement with User Input
int main() {
int number;
printf(“Enter a number: “);
scanf(“%d”, &number);
if(number > 0) {
printf(“Number is positive”);
}
return 0;
}
Multiple Conditions in If Statement
You can use relational and logical operators inside an if statement.
int main() {
int marks = 75;
if(marks >= 50 && marks <= 100) {
printf(“You passed the exam”);
}
return 0;
}
Why If Statement is Important
Key Benefits
- Enables decision-making
- Controls program flow
- Used in real-world applications
- Works with conditions and logic
Start Learning C Programming
Practice if statements with different conditions to improve your programming logic.
Summary
The if statement in C programming is used to execute code based on a condition. It is essential for decision-making and control flow.
FAQs
What is an if statement in C programming?
It is a control statement used to execute code when a condition is true.
What happens if the condition is false?
The code inside the if block is skipped.
Can we use multiple conditions in if?
Yes, using logical operators like && and ||.
Where is if statement used?
It is used in decision-making and conditional logic.



