---
title: "2.2 if-else Statement"
description: "The `if-else` statement selects between two blocks of code. The `if` block executes when the condition is non-zero; otherwise, the `else` block executes. ``` #include int main() { int number = -5; if (number > 0) { printf(\"The number is…"
url: "https://edcret.in/docs/c-programming/control-flow/2-2-if-else-statement/"
updated: "2026-09-06"
category: C Programming / Control Flow
---

# 2.2 if-else Statement

The `if-else` statement selects between two blocks of code. The `if` block executes when the condition is non-zero; otherwise, the `else` block executes.

```
#include <stdio.h>

int main()
{
    int number = -5;

    if (number > 0)
    {
        printf("The number is positive.\n");
    }
    else
    {
        printf("The number is not positive.\n");
    }

    return 0;
}
```

### Example Output

```
The number is not positive.
```

### Explanation

The condition is evaluated first:

```
if (number > 0)
```

Since `number` is `-5`, the condition evaluates to `0`. Therefore, the `if` block is skipped and the `else` block executes:

```
else
{
    printf("The number is not positive.\n");
}
```

Only one of the two blocks is executed for a single evaluation of the `if-else` statement.
