C if-else

It is a powerful decision-making statement. This statement is used to control the flow of execution of statements. if and else both are keywords. The normal flow of a program is altered by the if-else statement.

Syntax of if-else statement:

First of all, the condition is check and then, depending on whether the condition is true (non zero) or false (zero), it transfers the control to a particular statement.
If the condition is true then the statements inside the if block gets executed otherwise statements inside else block get executed.
if can be standalone but else cannot be standalone.

Flowchart of if-else statement:

if-else statement



Note: There should not be any statement between if and else.
If any statement exists between if and else then compiler gives an error.
For example:

The Condition of if will be any of the following to print output ‘hi’:

Forms of if-else statements

There are many forms of if statements, check out Forms of if: page for more details. These variations are used in different ways.

Help others by sharing the content!

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.