If  Statement

if statement allows to select an action based on some condition. It gives to take control over a piece of code. Programmer can control the execution of code based on some condition or user input.

For example - if user inputs valid account number and pin, then allow money withdrawal.

Syntax of if statement

 

if(boolean_expression)

{

    // body of if

}

 
Control Flow of Simple if Statement

#include <stdio.h>

void main()

{

    int age;

    printf("Enter your age: ");

    scanf("%d", &age);

    if(age >= 18)

    {

        printf("You are eligible to vote in India.");

    }

}

 
if statement flow chart

 

Back - C Language Notes By Vivek Sir email: vivekdubey22@gmail.com (w) 9826424484