Lecture 9b Flashcards

1
Q

What is the general syntax of an assignment statement?

A

<target_var> <assign_operator> <expression>
</expression></assign_operator></target_var>

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

Which languages use = and := as assignment operators?

A

= is used in Fortran, BASIC, and C-based languages; := is used in Ada.

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

How are conditional targets written in Perl?

A

($flag ? $total : $subtotal) = 0

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

What is a compound assignment operator and provide an example?

A

It is a shorthand for a commonly needed form of assignment. Example: a += b (equivalent to a = a + b).

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

What are unary assignment operators in C, C++, and Java, and how do they differ?

A

a++ increments after assignment; ++a increments before assignment.

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

How can assignment statements be used as expressions in C, C++, and Java?

A

Assignments return a result, allowing them to be used in expressions, e.g., while ((ch = getchar()) != EOF) { … }

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

Which languages allow multiple-target multiple-source assignments and provide an example?

A

: Perl, Ruby, Lua. Example: ($first, $second, $third) = (20, 30, 40);

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

How are assignments handled in functional languages like ML and F#?

A

Values are bound to names rather than allowing mutable variables. ML uses val, F# uses let.

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

How do Fortran, C, Perl, and C++ handle mixed-mode assignments?

A

A: They allow any numeric type value to be assigned to any numeric type variable.

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

How do functional and imperative assignments differ?

A

Functional assignments are referentially transparent and depend solely on the referencing environment. Imperative assignments are based on side effects and influence subsequent computation.

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

What do variables denote in the context of l-value and r-value?

A

l-value denotes a location in memory, while r-value denotes a value.

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

What is the difference between value and reference models in language design?

A

Value model directly manipulates values (Pascal, C, C++), while reference model variables refer to values (CLU, Java).

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

What is orthogonality in the context of programming languages?

A

It refers to the consistency and combinability of language features, ensuring that every combination of features works consistently. Algol 68 is an example of a language with orthogonal design.

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

What are the benefits of variable initialization and which languages provide it?

A

Initialization prevents errors and allows static allocation. Pascal does not provide it by default, while C, C++, and Ada support initialization of aggregates.

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

How do different languages handle uninitialized variables?

A

Pascal guarantees default values. C guarantees zero values only for static variables, while others may contain garbage values.

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

How do combination assignment operators simplify code in imperative languages?

A

They avoid repetition in frequent updates, e.g., a += 1 is simpler than a = a + 1.

17
Q

What is the purpose of the comma operator in C?

A

It allows sequencing operations, e.g., int a=2, b=3; a, b = 7, 6; results in a=2 and b=7.

18
Q

Why is the order of subexpression evaluation important?

A

It affects side effects and optimization. Some languages specify evaluation order (Java: left-to-right), while others leave it unspecified.

19
Q
A
20
Q
A