if statement in C

  • if statement is very powerful decision making statement.
  • C uses if statement to execute a specific set of statements when the given logical condition is true.
  • Here is a syntax of if statement as follows:
  • Syntax



    Statements ;

  • Statements present inside if block are executed only when the condition is true. In case the condition is false the compiler skips the statements within if block. Here is a diagram that represents the concept of if statement more clearly:
  • decision-making
  • Here is an example of if statement:




int main()


int a,b;

printf("\n Enter the value of a and b:");




printf("value of a and b are equal");



return 0;



The output of the above program is as follows:

Enter the value of a and b: 4


Value of a and b are equal