Header Ads

If keyword

The keyword if tells the compiler that what follows is a decision control instructions. The condition of the keyword is always enclosed within a pair of parentheses. If the condition, is true then the below statement is executed. If the condition is not true, then the statement is not executed instead the program skip to next step.The relational operators all same except for the equality operator == and the inequality operator != . Note that = is used for assignment, whereas == is used for comparison of two quantities.

Syntax :
if(this condition is true)
      execute this statement;
examples :
#include<stdio.h>
main()
{
int a;
printf("Enter the value of a : ");
scanf("%d",&a);
if(num < 10)
      printf("hello");
return 0;
}

If on the screen you type number less than 10 you get a message on the screen through printf( ). If you type some other number more than 10 the program doesn't do anything.

No comments