Back to Course
Control Flow

If...else statement in C Programming

What is if...else?

The if...else statement executes one block of code when a condition is true, and another block when it is false.

Syntax

if (condition) {
    // executes when condition is true
} else {
    // executes when condition is false
}

Example

int num = 7;
if (num % 2 == 0) {
    printf("Even number");
} else {
    printf("Odd number");
}

The else block is optional — it only runs when the if condition evaluates to false.

Ready to master real-world C Programming development?

Learn C Programming hands-on with mentor-led, live sessions.

Explore Course