If Statement with simple program

This is a conditional statement used in C to check condition or to control the flow of execution of statements. This is also called as ‘decision making statement or control statement.’ The execution of a whole program is done in one direction only.

If statement is used to validate only one condition i.e only one condition will be checked. Any statement, that is written for execution if certain condition is met, will be executed. No alternate condition will be checked.     

if statement

Syntax:

if(condition)

{

       statements;

}

In above syntax, the condition is checked first. If it is true, then the program control flow goes inside the braces and executes the block of statements associated with it. If it returns false, then program skips the braces. If there are more than 1 (one) statements in if statement then use { } braces else it is not necessary to use.

Note: C programming language assumes any non-zero and non-null values as true and if it is either zero or null then it is assumed as false value.

Program :

/*  Program to demonstrate if statement.

#include <stdio.h>

#include <conio.h>

void main()

{

       int age;

       age=20;

       clrscr();

       if(age>18)

              printf(“\n You are adult ”);

              getch();

}

Output will be : You are adult

Mohit Arora
Follow me