If Statement in C++

if statement:
The if statement is used to express the conditional expressions. If the given condition is true then it will execute the statements otherwise it will execute the optional statements.

The basic simple structure of the if statement is shown below:

The expression must be placed in round brackets as shown above. In this form, the set of statements would be executed only if the expression has a non-zero value (i.e., if expression is true). If the expression has a value zero (i.e., if expression is false), then the set of statements would be ignored by C++ compiler. The set of statements are skipped and the execution continues with the next statements.

Example:
Given below is a program which reads two numbers and then prints greater one using if statement.

You may also like...

1 Response

  1. September 15, 2013

    […] if statement […]

Leave a Reply

Your email address will not be published. Required fields are marked *