The associative operator, Has a value of 2, Table 4.1: operator precedence and associativity – Teledyne LeCroy CATC Scripting Language Reference Manual User Manual

Page 13

Advertising
background image

C

HAPTER

4

Operators

CATC Scripting Language

9


The associative operator

()

is used to group parts of the expression, forcing those

parts to be evaluated first. In this way, the rules of precedence can be overridden.
For example,

( 4 + 9 ) * 5

causes the addition to be performed before the multiplication, resulting in a value
of 65.

When operators of equal precedence occur in an expression, the operands are
evaluated according to the associativity of the operators. This means that if an op-
erator's associativity is left to right, then the operations will be done starting from
the left side of the expression. So, the expression

4 + 9 - 6 + 5

would evaluate to 12. However, if the associative operator is used to group a part or
parts of the expression, those parts are evaluated first. Therefore,

( 4 + 9 ) - ( 6 + 5 )

has a value of 2.

In Table 4.1, Operator Precedence and Associativity, the operators are listed in
order of precedence, from highest to lowest. Operators on the same line have equal
precedence, and their associativity is shown in the second column.

Operator Symbol

Associativity

++

--

Right to left

[]

()

Left to right

~

!

sizeof

head

tail

Right to left

*

/

%

Left to right

+

-

Left to right

<<

>>

Left to right

<

>

<=

>=

Left to right

==

!=

Left to right

&

Left to right

^

Left to right

|

Left to right

&&

Left to right

||

Left to right

Table 4.1: Operator Precedence and Associativity

Advertising