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.
Example
Output
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
Example