If else Statement In C Programming

If else Statement In C Programming

C Programming uses the keyword if and else to implement the decision control instruction.


If else Statement In C Programming


Syntax:

if (/* condition */)

{

    /* code */

}

else

{

    /* code */

}


If the condition is true then execute this statement ;  

Else execute 'this statement';


How if statement works in C ?


1. If the condition is evaluated to true,

  • code inside the body of if are executed.
  • code inside the body of else are skipped from execution.


2. If the condition is evaluated to false,

  • code inside the body of else are executed
  • code inside the body of if are skipped from execution.


Example


#include<stdio.h>


int main(){

    int a = 2, b = 3;

    if(a<b){

        printf("b is greater than a");

    }

    else{

        printf("a is greater than b")

    }

    return 0;

}


Output

b is greater than a

Flowchart of if else statement

If else Statement In C Programming


Load comments