14.2 Operators

王朝other·作者佚名  2006-01-10
窄屏简体版  字體: |||超大  

Expressions are constructed from operands and operators. The operators of an

expression indicate which

operations to apply to the operands. [Example: Examples of operators

include +, -, *, /, and new. Examples

of operands include literals, fields, local variables, and expressions. end

example]

There are three kinds of operators:

?Unary operators. The unary operators take one operand and use either

prefix notation (such as ?x) or

postfix notation (such as x++).

?Binary operators. The binary operators take two operands and all use

infix notation (such as x + y).

?Ternary operator. Only one ternary operator, ?:, exists; it takes three

operands and uses infix notation

(c ? x : y).

The order of evaluation of operators in an expression is determined by the

precedence and associativity of

the operators (?4.2.1).

The order in which operands in an expression are evaluated, is left to

right. [Example: For example, in

F(i) + G(i++) * H(i), method F is called using the old value of i, then

method G is called with the old

value of i, and, finally, method H is called with the new value of i. This

is separate from and unrelated to

operator precedence. end example] Certain operators can be overloaded.

Operator overloading permits userdefined

operator implementations to be specified for operations where one or both

of the operands are of a

user-defined class or struct type (?4.2.2).

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航