if Statement

if Statement

if Statement in C

The if statement is a decision making statement that allow us to control if a program executes a block of code or not, based on given conditions.

If condition is true, it will execute the block of code.

If condition is false, it will not execute the block of code.

Syntax

        
    if(conditions)
    {
        //Code
    }      
        
    

Program

        
#include <stdio.h>

int main ()
{
    int num = 15;   //Local variable definition
                
    if(num < 20)    //check the boolean condition using if statement
    {
        printf("num is less than 20\n" );    //if condition is true then print the following
    }
                
    printf("value of num is : %d\n", num);
    return 0;
}             
        
    

Output

        
num is less than 20
value of num is : 15             
        
    

Post a Comment

0 Comments