Common operator notation: Difference between revisions

Content deleted Content added
See also Operator (programming)
there is no postfix ! operator. also ++ and -- only work on lvalues.
Line 20:
 
A prefix or postfix operator is associative if and only if it may compete for operands with operators of equal precedence. The unary prefix operators '+', '−', and 'sin', for example, are all associative prefix operators. The unary postfix operator '!' and, in the [[C (programming language)|C]] language, the post-increment and post-decrement operators
"<tt>++</tt>" and "<tt>--</tt>" are examples of associative postfix operators. When more than one associative prefix or postfix operator of equal precedence precedes or succeeds an operand, the operators closer to the operand associate first. For example, −sin x = −(sin(x)) and, in [[C (programming language)|C]], the expression "<tt>x++--</tt>" is equivalent to "<tt>(x++)--</tt>". When prefix and postfix operators of equal precedence coexist, the order of association is undefined.
 
Note that, contrary to popular belief, prefix and postfix operators do not necessarily have higher precedence than all infix operators. For example, if the prefix operator 'sin' is given a precedence between that of '+' and '×',
Line 44:
Examples:
 
:<tt>1 + 2 + 3 * 4 * 5 + 6 + 7 == ((((1 + 2) + ((3 * 4) * 5)) + 6) + 7)</tt>
 
:<tt>4 + -x + 3 == ((4 + (-x)) + 3)</tt>
 
:<tt>4 * 3! = (4 * (3!))</tt>
 
:<tt>a++-- = (a++)--</tt>
 
:<tt>-3! = -(3!)</tt>
 
==Generalizations of Common Operator Notation==