×

# if in C

##### if statement in C programming, How to use if condition in C

In C programming if statement is used to check whether the given condition is true or not, if condition is true then the scope of if statement will be executed otherwise it will be skipped by the compiler.

## if Statement Syntax

• if statement is used to check only one condition at a time.
• In a single C program, we can use more than one if statement.
• if condition/expression is true then the scope of the if statement will run.
• if condition/expression is false then the scope of the if statement will not run.

## Value of Condition / Expression

In decision making statements when we say condition or expression, the meaning of both is the same so don't be confused between the condition and expression.

• In decision making, if the given condition is true then the value of condition/expression is 1
• In decision making, if the given condition is false then the value of condition/expression is 0
• In if expression a non zero number is always treated as truth whereas zero is treated as false.

#### Example

```int a=20, b=30, c=40;
the value of (a>b) is 0
the value of (b>a) is 1
the value of (b>c) is 0
the value of (a<c) is 1
```

## Combined Condition in if Statement

In if expression more than one condition can be combined together by using logical operators &&, ||, !

#### Example

A father promises his son that if he is 18+ and gets more than 60% marks in his exam, they will give him a bike, now write a C program which can check that his son is eligible for the bike or not.

#### Output

Note: Logical operator ! is used to convert true condition into false and false into true.

Let's take some real-time problem solutions with if condition in C programming.

### Program 1

Make a simple arithmetic calculator by using if statement in C programming.

#### Output

Note: There are no fixed and hard rules to use if condition in C programs, it depends on you how do you want to use if condition.

## Asked Questions

### Interview questions for freshers

Advertise With Us

We offer sponsored posts and guest posts with do-follow links, back-links, and other advertising services, To advertise email us at "advertise@gdatamart.com"

#### JOBS & TRAINING

© 2021 GDATAMART.COM (All Rights Reserved)