IF Condition in C tutorial

The keyword if tells the compiler that what follows is a decision control instruction. The condition following the keyword if is always enclosed within a pair of parentheses. If the condition, whatever it is, is true, then the statement is executed. If the condition is not true then the statement is not executed; instead the program skips past it

if ( this condition is true )
    execute this statement ;

The relational operators should be familiar to you except for the equality operator == and the inequality operator !=. Note that = is used for assignment, whereas, == is used for comparison of two quantities. Here is a simple program, which demonstrates the use of if and the relational operators.

/* i.e. */
main( )
{
      int num ;
      printf ( "Enter a number less than 10 " ) ;
      scanf ( "%d", &num ) ;
      if ( num <= 10 )
          printf ( "What an obedient servant you are !" ) ;
}


Comments

Popular Posts