FACTOID # 6: Clipperton Island wins our prize for the most unusual looking country.
 
 Home   Encyclopedia   Statistics   Countries A-Z   Flags   Maps   Education   Forum   FAQ   About 
 
WHAT'S NEW
RECENT ARTICLES
More Recent Articles »
 

FACTS & STATISTICS    Simple view

  1. Select countries to view: (hold down Control key and click to select several)

     

     

    Compare:

     

     

  1. Select fact or statistic: (* = graphable)

     

     

     

  2. (OPTIONAL) Compare to statistic: (both need to be graphable)

     

     

     

  3. View result as:

     

       
(OR) SEARCH ALL encyclopedia, stats & forums:   

Encyclopedia > Ternary operation

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. Wikibooks Wikiversity has more about this subject: School of Mathematics Wikiquote has a collection of quotations related to: Mathematics Look up Mathematics on Wiktionary, the free dictionary Wikimedia Commons has more media related to: Mathematics Bogomolny, Alexander: Interactive Mathematics Miscellany and Puzzles. ... In mathematics and computer programming the arity of a function or an operator is the number of arguments or operands it takes (arity is sometimes referred to as valency, although that actually refers to another meaning of valency in mathematics). ... A programming language or computer language is a standardized communication technique for expressing instructions to a computer. ...


In computer programming, especially in curly bracket programming languages, the ?: operator is known as the ternary operator or conditional operator. Its operands are one controlling expression whose value treated as a boolean, and two expressions. It evaluates to the value of the first expression if the controlling expression evaluates to true, and the value of the second expression if the controlling expression evaluates to false. For example: Wikibooks has more about this subject: Computer programming Computer programming (often simply programming) is the craft of implementing one or more interrelated abstract algorithms using a particular programming language to produce a concrete computer program. ... This article describes the use of balanced curly brackets ({ and }) in the syntax or formal grammar of mainly C-influenced programming languages. ... In computer science, the boolean datatype, sometimes called the logical datatype is a primitive datatype having two values, one and zero (in English: true and false). ...

 z = (x > y)? x: y; 

sets z to the maximum of x and y.


Some corporate programming guidelines list the use of the ternary operator as bad practice because it can harm readability and long-term maintainability. Also, an if statement can be debugged more easily than its ternary counterpart. However, ternary operators are widely used and can be useful in certain circumstances to avoid the use of an if statement, either because the extra verbiage would be too lengthy or because the syntactic context does not permit a statement. For example:

 #define MAX(a,b) (((a)>(b))? (a): (b)) 

or The C preprocessor is a preprocessor for the C programming language. ...

 for (i = 0; i < MAX_PATTERNS; i++) c_patterns[i].ShowWindow(m_data.fOn[i] ? SW_SHOW : SW_HIDE); 

  Results from FactBites:
 
Ternary - Wikipedia, the free encyclopedia (873 words)
Although ternary most often refers to a system in which the three digits, 0, 1 and 2, are all nonnegative integers, the adjective also lends its name to the balanced ternary system, useful for comparison logic.
Ternary is inefficient for human usage, just as binary is. Therefore, nonary (base 9, each digit is two ternary digits) or base 27 (each digit is three ternary digits) is often used, similar to how octal and hexadecimal systems are used in place of binary.
Ternary also has a unit similar to a byte, the tryte, which is six ternary digits.
  More results at FactBites »


 

COMMENTARY     


Share your thoughts, questions and commentary here
Your name
Your comments
Please enter the 5-letter protection code

Want to know more?
Search encyclopedia, statistics and forums:

 


Lesson Plans | Student Area | Student FAQ | Reviews | Press Releases |  Feeds | Contact
The Wikipedia article included on this page is licensed under the GFDL.
Images may be subject to relevant owners' copyright.
All other elements are (c) copyright NationMaster.com 2003-5. All Rights Reserved.
Usage implies agreement with terms.