đ if-else Condition in C
đ§Ē Short Explanation:
In C, if-else is used to choose between two blocks of code. If the condition is true, the if block runs; otherwise, the else block executes.
✅ Syntax
if (condition) {
// code if true
} else {
// code if false
}
đ Example
#include <stdio.h>
int main() {
int number = 10;
if (number % 2 == 0) {
printf("Even number\n");
} else {
printf("Odd number\n");
}
return 0;
}
đ§ Output: Even number
đĄ Use Cases
- Checking even or odd numbers
- Determining eligibility (e.g., age ≥ 18)
- Menu selections or user inputs
⚠️ Common Mistakes
- Using
=instead of==for comparison - Forgetting the curly braces
{ }for multiple lines - Leaving out the
elseblock when needed
đ Summary
The if-else structure is the foundation of decision-making in C programming. It helps direct program flow based on logical conditions.
āĻোāύ āĻŽāύ্āϤāĻŦ্āϝ āύেāĻ:
āĻāĻāĻি āĻŽāύ্āϤāĻŦ্āϝ āĻĒোāϏ্āĻ āĻāϰুāύ