CHAPTER 6

EXPRESSIONS AND ASSIGNMENT STATEMENTS

 

INTRO:

 

ARITHMETIC EXPRESSIONS

 

OPERATOR EVALUATION ORDER

 

PRECEDENCE

 

ASSOCIATIVITY

 

Language Associativity Rule

FORTRAN Left: *, /, +, -

Right: **

Pascal Left: All

C Left: postfix ++, postfix --, *, /, %, binary +, binary

Right: prefix ++, prefix --, unary +, unary

C++ Left: *, /, %, binary +, binary

Right: ++, --, unary -, unary +

Ada Left: all except **

Non-associative: **

 

PARENTHESES

 

CONDITIONAL EXPRESSIONS

If (count = 0)

Then average := 0

Else average := sum / count

Can become:

Average = (count == 0) ? 0 : sum / count;

 

 

OPERAND EVALUATION ORDER

SIDE EFFECTS

if FUN does not have the side effect of changing A, then the order of evaluation of the two operands, A and FUN(A), has no effect on the value of expression. But, if FUN changes A, there is an effect.

 

OVERLOADED OPERATORS

 

TYPE CONVERSIONS

 

 

COERCION IN EXPRESSIONS

 

RELATIONAL AND BOOLEAN EXPRESSIONS

 

RELATIONAL EXPRESSIONS

Operation Pascal Ada C FORTRAN77

Equal = = == .EQ.

Not equal <> /= != .NE.

Greater than > > > .GT.

Less than < < < .LT.

Greater than or equal >= >= >= .GE.

Less than or equal <= <= <= .LE.

 

BOOLEAN EXPRESSIONS

 

SHORT-CIRCUIT EVALUATION

 

ASSIGNMENT STATEMENTS

 

SIMPLE ASSIGNMENTS

<target_variable> <assignment_operator> <expression>

 

 

COMPOUND ASSIGNMENT OPERATORS

a = a + b

For example, sum += value;

Is equivalent to sum = sum + value;

 

UNARY ASSIGNMENT OERATORS

 

ASSIGNMENT AS AN EXPRESSION