• Home
  • 2.1 if Statement

2.1 if Statement

View Categories

2.1 if Statement

< 1 min read

Table of Contents

The if statement executes a block of code only when its condition evaluates to a non-zero value.

#include <stdio.h>

int main()
{
    int number = 10;

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

    return 0;
}

Example Output #

The number is positive.

Explanation #

The condition is specified inside the parentheses following if:

if (number > 0)

Here, number > 0 evaluates to 1 because number is 10. Since the condition is non-zero, the statement inside the block is executed:

printf("The number is positive.\n");

If the condition evaluates to 0, the block is skipped.

In C, an if condition is considered true when its value is non-zero and false when its value is zero.

Powered by BetterDocs

Leave a Reply

Your email address will not be published. Required fields are marked *