Content deleted Content added
operators in c are primitives |
No edit summary |
||
Line 25:
to allow loose typing. Defining it like this you are always aware of what the possible date you are dealing with is. It is true to say that loose typing should be used sparingly if possible. And you should be aware of the type retured from your operator and what the ''coerced'' effects are in the language you are using.
== Operator classification ==
Operators are binary or unary. Binary operators ("bi" as in "two") have two operands. In "A*B" the * operator has two operands: A and B. In "!B" the "!" operator (meaning boolean NOT) has only one operand, and is therefore a unary operator. The "-" and "+" operators can be both binary and unary, in "-4" or "+4" it denotes a negative or a positive number, in "0-4" it acts as the subtraction operator.
Operators have associativity. This defines the correct evaluation order if a sequence of the same operator is used one after another: whether the evaluator will evaluate the left operations first or the right. For example, in <tt>8 - 4 - 2</tt>, since subtraction in most languages is left associative, the so that expression evaluates left to right. <tt>8 - 4</tt> is evaluated first making restult 2, and not 6.
The ^ operator (sometime written **) is often right assosiative. So <tt>4^3^2</tt> equals <tt>4^9</tt>, not <tt>64^2</tt>.
{{comp-stub}}
|