Conditional operators in C

CONDITIONAL OR TERNARY OPERATORS IN C:

  • Conditional operators return one value if the condition is true and returns another value is the condition is false.
  • This operator is also called a ternary operator.
Syntax     :        (Condition? true_value: false_value);
Example :         (A > 100  ?  0  :  1);
  • In above example, if A is greater than 100, 0 is returned else 1 is returned. This is equal to if else conditional statements.

EXAMPLE PROGRAM FOR CONDITIONAL/TERNARY OPERATORS IN C:

OUTPUT:

x value is
y value is 2

No comments:

Post a Comment

Featured Post

Core and Advance Python

                      Language Fundamentals