# Ternary operation

(Redirected from Ternary operator)

In mathematics, a ternary operation is any operation of arity three, that is, that takes three arguments. A ternary operator (sometimes inaccurately referred to as a tertiary operator) is an operator that takes three arguments. A common form found in many programming languages is an operator that is used as shorthand for if-then-else statements. The general form is condition ? op1 : op2. If condition is true, the statement evaluates as op1; otherwise, it evaluates as op2.

In programming, especially in the C programming language, the "?:" operator is a ternary operator.

It takes in a boolean value, and two statements, and returns the return value of the first statement if the boolean value is true, and the return value of the second statement if the boolean value is false.

For example, the statement z = (x > y) ? x : y; assigns x to z if the value x is greater than y, and otherwise assigns y to z (the statement sets z equal to the maximum of x and y).

Some programmers regard using this ternary operator as bad practice, though it can be useful in certain circumstances to avoid excessive if statements.et:Ternaarne tehe

• Art and Cultures
• Countries of the World (http://www.academickids.com/encyclopedia/index.php/Countries)
• Space and Astronomy