Chapter 7 Flashcards

Expressions and Assignment Statements

1
Q

___ are the fundamental means of specifying computations in a programming language.

A

Expressions

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

It is crucial for a programmer to understand both the ___ and ___ of expressions of the used language.

A

syntax and semantics

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

To understand expression evaluation, it is necessary to be familiar with the ___ of ___ and ___ evaluation.

A

order, operator, operand

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

Although the value of an expression sometimes depends on it, the order of operand evaluation in expressions is often ___ by language designers.

A

unstated

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

Implementors being allowed to choose order of operand evaluations in expressions can lead to the possibility of programs producing ___ results in different implementations.

A

different

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

Other issues in expression semantics are ___ ___, ___, and ___-___ evaluation.

A

type mismatches, coercions, short-circuit

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

The essence of imperative programming languages is the ___ role of assignment statements.

A

dominant

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

The purpose of assignment statements in imperative languages is to cause the ___ ___ of changing the values of variables, or the state, of the program.

A

side effect

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

An integral part of all imperative languages is the concept of variables whose values change during program ___.

A

execution.

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

Functional languages use variables of a different sort, such as the parameters of ___.

A

functions

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

Functional languages, like imperative languages, also have declaration statements that bind values to ___.

A

names

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

Declarations of functional languages are similar to assignment statements, but do not have ___ ___

A

side effects

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

Automatic evaluation of arithmetic expressions similar to those found in mathematics, science, and engineering was one of the ___ of the first ___-___ programming languages.

A

goals, high-level

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

Most of the characteristics of arithmetic expressions in programming languages were inherited from convention that had evolved in ___.

A

mathematics.

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

In programming languages, arithmetic expressions consist of ___, ___, ___, and ___ ___.

A

operators, operands, parentheses, and function calls.

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

An operator can be ___, meaning it has a single operand, ___, meaning it has two operands, or ___, meaning it has three operands.

A

unary, binary, ternary

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

In most programming languages, binary operators are ___, which means they appear between their operands.

A

infix

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

Some languages, such as Perl, has some operators that are ___, which means they precede their operands.

A

prefix

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

Some languages have operators that are ___, which means they come after their operands.

A

postfix

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

The ___ precedence and ___ rules of a language dictate the order of evaluation of its operators.

A

operator, associativity

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

The ___ ___ rules for expression evaluation partially define the order in which the operators of different precedence levels are evaluated.

A

operator precedence rules

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

The operator precedence rules for expressions are based on the ___ of operator priorities, as seen by the language designer.

A

hierarchy

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

The operator precedence rules of the common imperative languages are nearly all the same, because they are based on those of ____.

A

mathematics

24
Q

Unary addition is called the ___ operator because it usually has no associated operation and thus has no effect on its operand.

A

identity

25
Q

Associatiativity in common languages is __ to __; however, there are exceptions in, such as in exponentiation in Fortran & Ruby which is ___ to __.

A

left to right; right to left

26
Q

An ___ exception can cause addition/subtraction not to be associative.

A

overflow

27
Q

All arithmetic and logic operations in Lisp are performed by ___.

A

subprograms

28
Q

If neither of the operands of and operator has ___ ___, then operand evaluation order is irrelevant.

A

side effects

29
Q

Operand evaluation order becomes relevant when there are ___ ___.

A

side effects

30
Q

A ___ ____ of a function, occurs when the function changes either one of its parameters or a global variable.

A

side effect

31
Q

Two possible solutions to the problem of operand evaluation order and side effects are:

A

1) Language designer could disallow functional side effects

2) The language definition could state that operands in expressions are to be evaluated in a particular order

32
Q

The problem with disallowing function side effects in the imperative languages is difficult and it eliminates some ___ for the programmer.

A

flexibility (i.e., disallowing access to global variables)

33
Q

The problem with having a strict evaluation order is that some code optimization techniques used by compilers involve ___ operand evaluations.

A

reordering

34
Q

A program has the property of ___ ___ if any two expressions in the program that have the same value can be substituted for one another anywhere in the program, without affecting the action of the program.

A

referential transparency

35
Q
result1 = (fun(a) + b / (fun(a) - c);
temp = fun(a)
result2 = (temp = b)/ (temp - c)

The example code above has referential transparency if ___?

A

result 1 = result2

36
Q

The most important advantage of referentially transparent programs is that the ___ of such programs is much easier to understand than those that are not referentially transparent.

A

easier

37
Q

Being referentially transparent makes a function equivalent to a ___ function, in terms of ease of understanding.

A

mathematical

38
Q

Because they do not have variables, programs written in pure ___ languages are referentially transparent.

A

functional

39
Q

Functions in a pure functional languages cannot have ___, which would be stored in local variables.

A

state

40
Q

The multiple use of an operator is called ___ ___ and is generally thought to be acceptable, as long as neither readability nor reliability suffers.

A

operator overloading

41
Q

A ___ conversion converts a value to a type that cannot store even approximations of all of the values of the original type.

A

Narrowing
Ex: converting a double to a float in Java is a narrowing conversion because the range of double is much larger than that of float.

42
Q

A ___ conversion converts a value to a type that can include at least all of the values of the original type.

A

Widening

43
Q

Between widening and narrowing conversions, ___ is nearly always safe, although they can result in ___ accuracy.

A

widening, reduced
ex: integer to float can be a loss in precision because both are stored in 32 bits; float allows for 7 decimal places while integer allows for 9 (in many language implementations)

44
Q

Expressions that allow operands of different types are called ___-___ expressions.

A

mixed mode

45
Q

Languages that allow mixed-mode expressions must define ___ for implicit operand type conversions.

A

conventions

46
Q

Explicit type conversions are called ___.

A

casts

47
Q

The most common error occurs when the result of an operation cannot be represented in the memory cell where it must be stored; this is called ___ or ___ depending on whether the result was too large or too small.

A

overflow, underflow

48
Q

Floating-point overflow, underflow, and division by zero are examples of run-time errors, which are sometimes called ___.

A

exceptions

49
Q

A ___ operator is an operator that compares the values of its two operands.

A

relational

50
Q

Unless not available in the language, the value of a relational expression is ___.

A

Boolean

51
Q

Boolean expressions consist of Boolean ___, Boolean ___, ___ ___, and Boolean ___.

A

variables, constants, relational expressions, operators (ex: AND OR NOT XOR)

52
Q

A ___-___ evaluation of an expression is one in which the result is determined without evaluating all of the operands and/or operators.

A

short-circuit

53
Q

(13 * a) * (b / 13 - 1) can be short-circuited when a = ___

A

0 because anything multiplied by 0 is 0

54
Q

The Boolean expression

(A >= 0) && (b < 10) can be short-circuited when

A

A < 10 because && dictates both statements must be true, if the first is false, no need to continue

55
Q

Programming languages that use an ___ as an assignment operator must use something different for the equality relational operator to avoid confusion with their assignment operator.

A

=

56
Q

A ___ assignment operator is a shorthand method of specifying a commonly needed form of assignment.

A

compound
ex: sum += value same as
sum = sum + value

57
Q

What are the two special unary arithmetic operators and what do they do?

A

++ increment, – decrements
ex: sum = ++ count (The value of count is incremented by 1 and assigned to sum)
sum = count ++ (The value of count is assigned to sum, then count is incremented