if in c

In c, if is a Decision making statement, allows to execute statement, if given condition is true.

Syntax

if(condition or expression)
{
 //set of statements
}

Example

void main()
{
   int age = 30;
   if(age < 50)
   {
      printf("age is %d", age);
   }
}
Output:
age is 30

Explanation

  1. variable age is declared and initialized with value 30.
  2. if condition or expression is checking weather age value is less than 50 or not.
  3. if condition returns true, then the statement inside if block, executes and outputs the value of variable age.