The if Statement in C

Like most languages, C uses the keyword if to implement the decision control instruction. The general form of if statement looks like this:

if ( this condition is true )
execute this statement ;

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. But how do we express the condition itself in C? And how do we evaluate its truth or falsity? As a general rule, we express a condition using C’s ‘relational’ operators. The relational operators allow us to compare two values to see whether they are equal to each other, unequal, or whether one is greater than the other. Here’s how they look and how they are evaluated in C.

this expressionis true if
x == yx is equal to y
x != yx is not equal to y
x < yx is less than y
x > yx is greater than y
x <= yx is less than or equal to y
x >= yx is greater than or equal to y
The if Statement in C

/* Demonstration of if statement */

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

Leave a Comment