Chapter 7 Flashcards

Expressions and Assignment Statements (57 cards)

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 ____.

24
Q

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

25
Associatiativity in common languages is __ to __; however, there are exceptions in, such as in exponentiation in Fortran & Ruby which is ___ to __.
left to right; right to left
26
An ___ exception can cause addition/subtraction not to be associative.
overflow
27
All arithmetic and logic operations in Lisp are performed by ___.
subprograms
28
If neither of the operands of and operator has ___ ___, then operand evaluation order is irrelevant.
side effects
29
Operand evaluation order becomes relevant when there are ___ ___.
side effects
30
A ___ ____ of a function, occurs when the function changes either one of its parameters or a global variable.
side effect
31
Two possible solutions to the problem of operand evaluation order and side effects are:
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
The problem with disallowing function side effects in the imperative languages is difficult and it eliminates some ___ for the programmer.
flexibility (i.e., disallowing access to global variables)
33
The problem with having a strict evaluation order is that some code optimization techniques used by compilers involve ___ operand evaluations.
reordering
34
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.
referential transparency
35
``` result1 = (fun(a) + b / (fun(a) - c); temp = fun(a) result2 = (temp = b)/ (temp - c) ``` The example code above has referential transparency if ___?
result 1 = result2
36
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.
easier
37
Being referentially transparent makes a function equivalent to a ___ function, in terms of ease of understanding.
mathematical
38
Because they do not have variables, programs written in pure ___ languages are referentially transparent.
functional
39
Functions in a pure functional languages cannot have ___, which would be stored in local variables.
state
40
The multiple use of an operator is called ___ ___ and is generally thought to be acceptable, as long as neither readability nor reliability suffers.
operator overloading
41
A ___ conversion converts a value to a type that cannot store even approximations of all of the values of the original type.
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
A ___ conversion converts a value to a type that can include at least all of the values of the original type.
Widening
43
Between widening and narrowing conversions, ___ is nearly always safe, although they can result in ___ accuracy.
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
Expressions that allow operands of different types are called ___-___ expressions.
mixed mode
45
Languages that allow mixed-mode expressions must define ___ for implicit operand type conversions.
conventions
46
Explicit type conversions are called ___.
casts
47
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.
overflow, underflow
48
Floating-point overflow, underflow, and division by zero are examples of run-time errors, which are sometimes called ___.
exceptions
49
A ___ operator is an operator that compares the values of its two operands.
relational
50
Unless not available in the language, the value of a relational expression is ___.
Boolean
51
Boolean expressions consist of Boolean ___, Boolean ___, ___ ___, and Boolean ___.
variables, constants, relational expressions, operators (ex: AND OR NOT XOR)
52
A ___-___ evaluation of an expression is one in which the result is determined without evaluating all of the operands and/or operators.
short-circuit
53
(13 * a) * (b / 13 - 1) can be short-circuited when a = ___
0 because anything multiplied by 0 is 0
54
The Boolean expression | (A >= 0) && (b < 10) can be short-circuited when
A < 10 because && dictates both statements must be true, if the first is false, no need to continue
55
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.
=
56
A ___ assignment operator is a shorthand method of specifying a commonly needed form of assignment.
compound ex: sum += value same as sum = sum + value
57
What are the two special unary arithmetic operators and what do they do?
++ 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