BookRags.com Literature Guides Literature
Guides
Criticism & Essays Criticism &
Essays
Questions & Answers Questions &
Answers
Lesson Plans Lesson
Plans
My Bibliography Periodic Table U.S. Presidents Shakespeare Sonnet Shake-Up
Research Anything:        
History | Encyclopedias | Films | News | Create a Bibliography | More... Login | Register | Help
Not What You Meant?  There are 20 definitions for Tertiary.  Also try: Ternary.

Ternary operation

Print-Friendly
About 1 pages (359 words)

Bookmark and Share Know this topic well? Help others and get FREE products!

In mathematics, a ternary operation is an n-ary operation with n = 3. A ternary operation on a set A takes any given three elements of A and combines them to form a single element of A. An example of a ternary operation is the product in a heap. In computer science a ternary operator is an operator that takes three arguments. The arguments and result can be of different types. Many programming languages that use C-like syntax feature a ternary operator, ?:, which defines a conditional expression. Since this operator is often the only existing ternary operator in the language, it is sometimes simply referred to as "the ternary operator". The ternary conditional operator was anticipated by ALGOL, which allowed if then else to be used in expressions, for example:

a := if x > 0 then x else -x.

Languages that emphasize functional programming, such as Scheme, may define the plain if-then-else construction in terms of this ternary operator. For example, the Scheme expression (if (> a b) a b) is equivalent in semantics to the C expression (a > b) ? a : b. Though it had been delayed for several years by disagreements over syntax, a ternary operator for Python was approved as Python Enhancement Proposal 308 and was added to the 2.5 release in September 2006. Python's ternary operator differs from the common ?: operator in the order of its operands; the general form is op1 if condition else op2. This form invites considering op1 as the normal value and op2 as an exceptional case. Programming languages in the Visual Basic family instead use a library function, IIf, with syntax iif(condition, op1, op2). This has significant disadvantages, because the subexpressions must all be evaluated, according to Visual Basic's evaluation strategy for function calls.

See also

  • ?:, the ternary conditional expression
  • IIf, inline if function

External links

View More Summaries on Ternary operation
 
Ask any question on Ternary operation and get it answered FAST!
Answer questions in BookRags Q&A and earn points toward
discounted or even FREE Study Guides and other BookRags products!
Learn more about BookRags Q&A
Copyrights
Ternary operation from Wíkipedia. ©2006 by Wíkipedia. Licensed under the GNU Free Documentation License. View a list of authors or edit this article.

Article Navigation
Join BookRagslearn moreJoin BookRags




About BookRags | Customer Service | Report an Error | Terms of Use | Privacy Policy