CHAPTER 7 - Expressions and Assignment Statements

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/40

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 8:24 PM on 5/20/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

41 Terms

1
New cards

Expressions

the fundamental means of specifying computations in a programming language

2
New cards

4 components of arithmetic expressions

Operators -- Operands -- Parentheses -- Function Calls

3
New cards

3 types of operators by operand count

Unary (1 operand) -- Binary (2 operands) -- Ternary (3 operands)

4
New cards

Ternary operator

has three operands -- used in C-based languages as a conditional expression -- syntax: expression_1 ? expression_2 : expression_3

5
New cards

2 actions of arithmetic expression implementation

fetching operands from memory -- executing arithmetic operations on those operands

6
New cards

6 design issues for arithmetic expressions

operator precedence rules -- operator associativity rules -- order of operand evaluation -- restrictions on side effects -- user-defined operator overloading -- mode mixing in expressions

7
New cards

Operator Precedence

defines the order in which operators of different precedence levels are evaluated

8
New cards

Unary Addition (+)

called the identity operator -- no associated operation -- no effect on its operand

9
New cards

Unary Minus (-) in Java/C#

causes implicit conversion of short and byte operands to int type

10
New cards

Operator Associativity

defines the order in which adjacent operators with the same precedence level are evaluated -- can be left or right associative

11
New cards

Typical associativity

left to right -- except ** which is right to left

12
New cards

APL associativity

all operators have equal precedence -- all associate right to left

13
New cards

Overriding precedence and associativity

done with parentheses

14
New cards

Functional side effect

occurs when a function changes one of its parameters or a global variable

15
New cards

2 solutions to functional side effects

write language definition to disallow side effects -- write language definition to demand fixed operand evaluation order

16
New cards

Java operand evaluation order

guarantees left-to-right order -- eliminates side effect ambiguity

17
New cards

Operator Overloading

the use of an operator for more than one purpose

18
New cards

& in C/C++ -- overloading problem

unary: address-of operator -- binary: bitwise AND -- using the same symbol for two unrelated operations harms readability

19
New cards

in Java -- overloading

addition for numbers -- string catenation for strings

20
New cards

Languages allowing user-defined operator overloading

C++ -- C# -- F#

21
New cards

2 potential problems of user-defined operator overloading

users can define nonsense operations -- readability may suffer

22
New cards

Narrowing Conversion

converts an object to a type that cannot include all values of the original type -- example: double to float

23
New cards

Widening Conversion

converts an object to a type that can include at least approximations to all values of the original type -- example: int to float

24
New cards

Coercion in Expressions

implicit type conversion in a mixed-mode expression -- disadvantage: decreases type error detection ability of the compiler

25
New cards

Mixed-mode expression

an expression that has operands of different types

26
New cards

Languages with no coercions in expressions

ML -- F#

27
New cards

Mixed-mode assignment -- Fortran/C/C++

any numeric value can be assigned to any numeric scalar variable

28
New cards

Mixed-mode assignment -- Java/C#

only widening assignment coercions are done

29
New cards

Mixed-mode assignment -- Ada

no assignment coercion

30
New cards

Casts

explicit type conversions in the C-based languages

31
New cards

Relational Operator

an operator that compares the values of its two operands -- result is Boolean

32
New cards

Boolean in C (before C99)

no Boolean type -- uses int -- 0 is false -- nonzero is true

33
New cards

Short-Circuit Evaluation

result is determined without evaluating all operands and/or operators

34
New cards

Equal sign

Assignment operator symbols in ALGOL, Pascal, Ada

35
New cards

Compound Assignment Operators

shorthand where destination variable also appears as first operand on the right side

36
New cards

Unary Assignment Operators (++ and --)

combine increment/decrement with assignment -- can be prefix or postfix

37
New cards

Prefix ++ behavior

increments first then uses the value

38
New cards

Postfix ++ behavior

uses the value first then increments

39
New cards

Assignment as an Expression

treats assignment operator like a binary operator -- has side effect of changing its left operand -- leads to difficult-to-read expressions -- common source of errors in C

40
New cards

Multiple Assignments

languages that support multiple-target multiple-source assignments: Perl -- Ruby -- Lua

41
New cards

Assignment in Functional Languages

identifiers are only names of values -- no mutable assignment