Skip to main content

Syntax of if...else

Short answer

if (condition) { statements; } else { statements; } executes the first block when condition is true, otherwise the second block. Exactly one branch runs.

Write the syntax used in C programming language for if...else.

Syntax:

if (condition)
{
    statements executed when the condition is true;
}
else
{
    statements executed when the condition is false;
}

Exactly one of the two blocks executes. A chain is written as if ... else if ... else.

Example:

#include <stdio.h>
int main(void)
{
    int n = 7;
    if (n % 2 == 0)
        printf("Even\n");
    else
        printf("Odd\n");
    return 0;
}

Output:

Odd

✓ Answer checked by Claude Opus 5.5 (high effort)

All Computer Programming chapter 5 questions →