If expression is nonzero when evaluated, then statement1 is executed. In the second case, statement2 is executed if the expression is 0.
An optional else can follow an if statement, but no statements can come between an if statement and an else.
Of course, both statement1 and statement2 may be compound statements (i.e. a sequence of statements enclosed in braces).
if (expression)
statement1
Alternatively, if may be used together with else, using the following syntax:
if (expression)
statement1
else
statement2
Example:
void main()
{
int x = 10;
int y = 5;
if (x < y)
{
printf ("x is smaller");
}
else
{
printf ("x is greater");
}
}
Output:
x is greater