if Statement

Written by

studymite

if Statement

 

 

if statement : In C language the if keyword tells the compiler to check the condition enclosed in the parenthesis. If the condition inside the parentheses is true then then the statements are executed and if the condition inside the parenthesis is false then the statements are not executed and thus, skipped.

The if statement looks like this:

                   
 if(this condition is true)
 {
   execute this statement;
 }

Example :

                   
    #include <stdio.h>
int main()
{
  int num;
  printf(“Enter a number: ”);
  scanf(“%d”,&amp;num);
    if(num &lt; 50)
        {
            printf(“Number is less than 50.”);
        }

  return 0;
}

Output :

Enter a number: 25        //Input
Number is less than 50.   //Output

In the above example, if the number is less than 50, than the statement will run else the printf statement will be skipped.

if Statement