Chapter 7 - Expressions and Assignment Statements Flashcards

1
Q

What are the 6 design issues with arithmetic expressions?

A

1) what are operator precedence rules
2) what the operator associativity rules
3) what is the order of operand evaluation
4) are there restrictions on operand evaluation side effects?
5) is user-defined operator overloading allowed?
6) what mode mixing is allowed in expressions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the definitions of unary, binary and ternary operators

A

unary = has one operand

binary = has two operands

ternary = has three operands

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the typical order of operator precedence

A
parentheses
unary operators
** (exponentiation)
*,/
\+,-

just like you learned in middle school

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Examples of unary operators

A

’-‘ (ex: -5 changes five to its negative value)

’+’ (ex: +5 this is valid syntax but it does ABSOLUTELY NOTHING)

’++’ and ‘–’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are the typical associativity rules?

A

exactly what you learned in school for the most part

left to right

EXCEPT for exponentiation operator which is right-to-left so:

2 ** 3 ** 4 == 2 ** (3 ** 4)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the order of operand evaluation?

A

1) variable - fetch the values
2) constants - fetch value
3) parenthesized expressions (evaluate fully)
4) function references

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

definition of functional side effects

A

when a function changes a two-way parameter or non-local variable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

2 solutions for handling expressions containing function references that produce functional side effects relevant to other values in the expression

A

1) don’t allow function side effects by disallowing two-way parameters and non-local references
2) make the language force operand evaluation order to be fixed

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

2 disadvantages of operator overloading

A

detriment to readability

loss of compiler error detection

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

definition of narrowing conversion

A

one that converts an object to a type that may not be able to hold some of the possible values of the original type

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

definition widening conversion

A

one that converts an object to a type that can at least approximate all the possible values of the original type if not hold them exactly

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

definition of a mixed-mode expression

A

an expression that contains operands of different types

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Explicit type conversion vs implicit type conversion

A

explicit = conversion performed by some directive provided by the programmer (ie. casting)

implicit = conversion performed by the compiler with no directive from the programmer (ie, narrowing and widening conversions, coercion)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

definition of a relational operator

A

an operator that compares the values of its two operands. The result of a relational expression is a boolean

ex) ==, !=

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Precedence arithmetic ops, relational ops, and boolean ops

A
highest
 -postfix arithmetic ops (++ and --)
-unary ops
normal arithmetic ops
relational ops: less than/greater than
relational ops:  equal/not equal
boolean ops: AND
boolean ops OR
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

definition of short-circuit evaluation

A

an expression which can be fully evaluated without evaluating all of the operands and/or operators

ex: a < 5 && b > 10 (if a=6 then the expression will always be false regardless of the value of b)

a*(b-2) (if a=0, then the expression will always equal 0 regardless of the value of b)

17
Q

Which PLs default to short-circuit boolean expressions?

A
C-based
Perl
Ruby
Python
ML