|
In computer programming, ?: is a ternary operator that is part of the syntax for a basic conditional expression in several programming languages. It is commonly referred to as the conditional operator, inline if (iif), or ternary if.It originally comes from CPL, in which equivalent syntax for ''e''1 ? ''e''2 : ''e''3 was ''e''1 → ''e''2, ''e''3 .〔(【引用サイトリンク】 work = BCPL Reference Manual )〕Although many ternary operators are possible, the conditional operator is so common, and other ternary operators so rare, that the conditional operator is commonly referred to as ''the'' ternary operator. ==Conditional assignment== ?: is used as follows:: ''condition'' ? ''value_if_true'' : ''value_if_false'' The ''condition'' is evaluated ''true'' or ''false'' as a Boolean expression. On the basis of the evaluation of the Boolean condition, the entire expression returns ''value_if_true'' if ''condition'' is true, but ''value_if_false'' otherwise. Usually the two sub-expressions ''value_if_true'' and ''value_if_false'' must have the same type, which determines the type of the whole expression. The importance of this type-checking lies in the operator's most common use—in conditional assignment statements. In this usage it appears as an expression on the right side of an assignment statement, as follows: : ''variable'' = ''condition'' ? ''value_if_true'' : ''value_if_false'' The ?: operator is similar to the way conditional expressions (if-then-else constructs) work in functional programming languages, like Scheme, ML, and Haskell, since if-then-else forms an expression instead of a statement in those languages. 抄文引用元・出典: フリー百科事典『 ウィキペディア(Wikipedia)』 ■ウィキペディアで「?:」の詳細全文を読む スポンサード リンク
|