added ternary operation to conditional statements (#22773)

This commit is contained in:
Blaze2305
2018-11-15 11:17:04 +05:30
committed by Aditya
parent beadff7771
commit e7cc0c6d1a

View File

@ -234,6 +234,7 @@ printf("%.1lf / %.1lf = %.1lf",firstNumber, secondNumber, firstNumber/firstNumbe
Finally, the break statement ends the switch statement. Finally, the break statement ends the switch statement.
If break statement is not used, all cases after the correct case is executed. If break statement is not used, all cases after the correct case is executed.
## finding the Bigger among two numbers using if else statement. ## finding the Bigger among two numbers using if else statement.
```C ```C
int a,b; int a,b;
@ -251,3 +252,22 @@ else
printf("B is the bigger number"); printf("B is the bigger number");
} }
``` ```
## 6. Ternary operation
The ternary operator (AKA conditional operator) is an operator that takes three arguments. The first argument is a comparison argument, the second is the result upon a true comparison , and the third is the result upon a flase comparison .It can be thought of as a shortened way of writing an if-else statement. It is often used to to assign variables based on the result of a comparison.
#### Syntax
```C
v = (conditional_statement) ? value_if_true : value_if_false
```
#### Example
```C
int a, b = 10, c = 100;
a = (b > c) ? 1 : 2;
printf("%d", a);
```
#### Result
`2`