Control Structures

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/51

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

52 Terms

1
New cards

what is a command in programming languages?

a construct that performs and action does not return a value

2
New cards

give examples of commands

assignment statements, if statements, while statements, void function/procedure calls

3
New cards

can commands be written where expressions normally appear?

depends on the language. some languages treat certain commands as expressions with values

4
New cards

basic form of an assignment?

l value = r-value

5
New cards

what is the difference between l-values and r-values?

  • l-value: identifies a storage location

  • r-value: provides a value to be stored there

6
New cards

what common error occurs due to = being allowed in expressions?

using = instead of == in conditionals

7
New cards

copy semantics?

assignment copies the value of the right side into the left side. subsequent changes do not affect each other

8
New cards

reference semantics?

assignment makes both variables refer to the same underlying object. changing one affects the other

9
New cards

languages that use copy semantics?

Pascal, C, Ada, most built-in types in Java, default behavior in C++

10
New cards

languages that use reference semantics?

LISP and Java for all objects

11
New cards

in copy semantics, what does x = y; do?

copies the value of y into x. they become independent

12
New cards

what can serve as an l-value?

x, A[i], rec.field

13
New cards

what can’t serve as an l-value?

expressions that only yield values, such as x+y, 23, foo(x)

14
New cards

what is a shallow copy?

copy the pointer value; the new object refers to the same inner objects.

15
New cards

what is a deep copy?

copy the entire object graph; internal referenced objects are duplicated

16
New cards

which languages normally perform shallow copies?

C, Pascal, Ada, Java

17
New cards

why may shallow copy be insufficient?

mutating a shared referenced object changes both copies — unexpected aliasing.

18
New cards

why does C++ allow custom assignment operators and copy instructors?

to allow the programmer to implement deep copy when needed

19
New cards

what distinguishes a command from an expression?

commands are statements with effects but no return value; expressions compute and return a value

20
New cards

in C/Java, is = an opeator?

yes — = returns the assigned value

21
New cards

what enables code like a = b = c = 0; ?

assignment being an expression that associates right-to-left

22
New cards

what is a danger of assignment-as-expression?

using = instead of == inside conditionals

23
New cards

what two features define imperative PLs?

assignment and control flow

24
New cards

what is control flow?

the specific statement currently being executed

25
New cards

what is a basic block?

a consecutive sequence of statements with single entry and single exit

26
New cards

what does GOTO do?

unconditional branch to labeled statement

27
New cards

what is an arithmetic IF?

IF (expr) s, t, u → go to label based on negative/zero/positive

28
New cards

why was early FORTRAN known for “spaghetti code”?

arbitrary jumps created tangled, nonstructured flow.

29
New cards

what is structured programming?

programs composed only of single-entry/single-exit constructs: sequencing, selection, iteration

30
New cards

what is sequencing?

grouping statements into ordered blocks with one entry and exit

31
New cards

what problem does structured programming solve in selection statements?

ensures nested structure matches control-flow intent

32
New cards

what is a dangling else?

ambiguity of which if an else belongs to

33
New cards

what is a definite loop?

number of iterations known at loop entry

34
New cards

why is the C for loop flexible?

initialization, condition, and increment are arbitrary statements/expressions

35
New cards

what are the three major syntactic forms of expressions?

infix, prefix, postfix

36
New cards

write x * (y+1) - z in postfix

x y 1 + * z -

37
New cards

write x * (y+1) - z in prefix

- * x + y 1 z

38
New cards

why can all three forms be generated from an AST?

because the AST captures structure independent of notation

39
New cards

what tree traversal produces postfix notation?

post-order traversal

40
New cards

why is postfix easy to evaluate?

because operators come after operands, enabling stack-based evaluation

41
New cards

what is the general algorithm for evaluating postfix?

  1. read tokens left to right

  2. push operands

  3. on operator: pop two operands, apply operator, push result

42
New cards

why does short-circuiting change observable behavior?

because operands may have side effects; skipping evaluation means skipping side effects

43
New cards

why is short-circuiting important?

  • prevents invalid operations

  • prevents unwanted side effects

44
New cards

when does the second operand of expr1 || expr2 get evaluated?

only when expr1 is false

45
New cards

when does the second operand of expr1 && expr2 get evaluated?

only when expr1 is true

46
New cards

what does short-circuiting mean?

the second operand is evaluated only if needed

47
New cards

what must conditional operator code generation include?

branching logic (Jump to L1/L2)

48
New cards

what is the idea behind postfix code generation?

generate the code that pushes operands, then pops them wehn applying operators

49
New cards

what does the non-stack method use instead of stack pushes/pops?

temporary variables

50
New cards

why is this approach often faster?

accessing temporaries is quicker than stack operations

51
New cards

why is memory cost not as bad as it seems?

optimizers often merge temporary variables

52
New cards

what is a side effect?

any effect of evaluating an expression beyond producing a value

Explore top flashcards

BPH
Updated 628d ago
flashcards Flashcards (36)
Unit 7 Vocab
Updated 666d ago
flashcards Flashcards (24)
AMENDMENTS
Updated 231d ago
flashcards Flashcards (22)
Avancemos 2 U4.1
Updated 330d ago
flashcards Flashcards (37)
Monatomic ioons
Updated 802d ago
flashcards Flashcards (30)
The CNSS Model
Updated 259d ago
flashcards Flashcards (20)
chem stu guide 1
Updated 921d ago
flashcards Flashcards (80)
BPH
Updated 628d ago
flashcards Flashcards (36)
Unit 7 Vocab
Updated 666d ago
flashcards Flashcards (24)
AMENDMENTS
Updated 231d ago
flashcards Flashcards (22)
Avancemos 2 U4.1
Updated 330d ago
flashcards Flashcards (37)
Monatomic ioons
Updated 802d ago
flashcards Flashcards (30)
The CNSS Model
Updated 259d ago
flashcards Flashcards (20)
chem stu guide 1
Updated 921d ago
flashcards Flashcards (80)