Easy Tutorial
❮ C Exercise Example71 C Sort Algorithm ❯

If Statement

C Decision

An if statement consists of a Boolean expression followed by one or more statements.

Syntax

The syntax for an if statement in C language is:

if(boolean_expression)
{
   /* Statements to execute if the Boolean expression is true */
}

If the Boolean expression evaluates to true, the block of code inside the if statement is executed. If the Boolean expression evaluates to false, the first set of code after the closing bracket of the if statement is executed.

C language considers any non-zero and non-null values as true, and zero or null as false.

Flowchart

Example

Example

#include <stdio.h>

int main ()
{
   /* Local variable definition */
   int a = 10;

   /* Check the Boolean condition using if statement */
   if( a < 20 )
   {
       /* Print the following statement if the condition is true */
       printf("a is less than 20\n" );
   }
   printf("The value of a is %d\n", a);

   return 0;
}

When the above code is compiled and executed, it produces the following result:

a is less than 20
The value of a is 10

C Decision

❮ C Exercise Example71 C Sort Algorithm ❯