C Nested if-else Statements

Nested if else statements play an important role in C programming, it means you can use conditional statements inside another conditional statement.

The basic format of Nested if else statement is:

Syntax:
if(test_expression one)
{
   if(test_expression two) {
      //Statement block Executes when the boolean test expression two is true.
   }
}
else
{
    //else statement block
}

Example of a C Program to Demonstrate Nested if-else Statement

Example:
#include<stdio.h>

main()
{
int x=20,y=30;

    if(x==20)
    {
        if(y==30)
        {
            printf("value of x is 20, and value of y is 30.");
        }
    }
}

Execution of the above code produces the following result.

Output:
value of x is 20, and value of y is 30.