Conditional or ternary operators in C:
Code:
Output:
- Conditional operators return one value if condition is true and returns another value is condition is false.
- This operator is also called as ternary operator.
- In above example, if A is greater than 100, 0 is returned else 1 is returned. This is equal to if else conditional statements.
Syntax : (Condition? true_value: false_value);
Example : (A > 100 ? 0 : 1);
Code:
#include <stdio.h> int main() { int x=1, y ; y = ( x ==1 ? 2 : 0 ) ; printf("Value of x is %d\n", x); printf("Value of y is %d", y); }
Value of x is 1 Value of y is 2
0 Comments For "Conditional or Ternary Operators In C"