Content deleted Content added
Moggie2002 (talk | contribs) Add the origins from BCPL, note that PHP botched the implementation of this operator |
|||
Line 1:
{{Unreferenced|date=November 2007}}
'''<code>?:</code>''' is a [[ternary operator]] that is part of the syntax for a basic [[conditional statement|conditional expression]] in several [[programming language]]s including [[C (programming language)|C]], [[Objective-C]], [[C++]], [[C Sharp (programming language)|C#]], [[D programming language|D]], [[Java (programming language)|Java]], [[JavaScript]], [[Linoleum programming language|Linoleum]], [[Perl]], [[PHP]], [[Tcl]], [[Ruby programming language|Ruby]], and [[Verilog]]. Its origin comes from [[BCPL]], whose equivalent syntax for E1 ? E2 :E3 was E1 -> E2, E3. Languages derived from BCPL tend to feature this operator.
==Conditional assignment==
Line 90:
</source>
This is much more readable and is more immediately recognized than the <code>if</code> statement equivalent.
== Inconsistency of Implementations ==
Due to an unfortunate error in the language grammar, the implementation of ?: in the PHP language uses the incorrect associativity when compared to other languages, and given a value of '''T''' for '''arg''', the PHP equivalent of the above example would yield the value '''horse''' instead of '''train''' as one would expect.
== Conditional jumps ==
|