Chapter 4: operators, 1 operations, 2 operator precedence and associativity – Teledyne LeCroy Protocol Analyzers File-Based Decoding User Manual User Manual

Page 15: Chapter 4, Operators

Advertising
background image

File-based Decoding User Manual

Chapter 4: Operators

LeCroy Corporation

9

Chapter 4: Operators

An operator is a symbol that represents an action, such as addition or subtraction, that
can be performed on data. Operators are used to manipulate data. The data being
manipulated are called operands. Literals, function calls, constants, and variables can
all serve as operands. For example, in the operation

x + 2

the variable x and the integer 2 are both operands, and + is the operator.

4.1 Operations

Operations can be performed on any combination of value types, but results in a null
value if the operation is not defined. Defined operations are listed in the Operand Types
column of Table 4.2 on page 11. Any binary operation on a null and a non-null value
results in the non-null value. For example, if

x = null

then

3 * x

returns a value of 3.

A binary operation is an operation that contains an operand on each side of the operator,
as in the preceding examples. An operation with only one operand is called a unary
operation, and requires the use of a unary operator. An example of a unary operation is

!1

which uses the logical negation operator. It returns a value of 0.

4.2 Operator Precedence and Associativity

Operator rules of precedence and associativity determine in what order operands are
evaluated in expressions. Expressions with operators of higher precedence are
evaluated first. In the expression

4 + 9 * 5

the * operator has the highest precedence, so the multiplication is performed before the

addition. Therefore, the expression evaluates to 49.

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.

Advertising