Dog Breeds Information and More
  Komondor - Dog Breeds Facts and Information Dog Breeds Selector A to Z dog breeds Forums

 
Dog names
Dog training
Toy dogs
Intelligence
Dog health
Dog worship
Ticks

 
Golden Retriever
Labrador Retriever
Jack Russell
 
Find a Breed
 
Dog Breeds Encyclopedia
 

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, z = (x > y) ? x : y; assigns x to z if 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.

The contents of this article are licensed from Wikipedia.org under the
GNU Free Documentation License. How to see transparent copy