Lecture 9b Flashcards
What is the general syntax of an assignment statement?
<target_var> <assign_operator> <expression>
</expression></assign_operator></target_var>
Which languages use = and := as assignment operators?
= is used in Fortran, BASIC, and C-based languages; := is used in Ada.
How are conditional targets written in Perl?
($flag ? $total : $subtotal) = 0
What is a compound assignment operator and provide an example?
It is a shorthand for a commonly needed form of assignment. Example: a += b (equivalent to a = a + b).
What are unary assignment operators in C, C++, and Java, and how do they differ?
a++ increments after assignment; ++a increments before assignment.
How can assignment statements be used as expressions in C, C++, and Java?
Assignments return a result, allowing them to be used in expressions, e.g., while ((ch = getchar()) != EOF) { … }
Which languages allow multiple-target multiple-source assignments and provide an example?
: Perl, Ruby, Lua. Example: ($first, $second, $third) = (20, 30, 40);
How are assignments handled in functional languages like ML and F#?
Values are bound to names rather than allowing mutable variables. ML uses val, F# uses let.
How do Fortran, C, Perl, and C++ handle mixed-mode assignments?
A: They allow any numeric type value to be assigned to any numeric type variable.
How do functional and imperative assignments differ?
Functional assignments are referentially transparent and depend solely on the referencing environment. Imperative assignments are based on side effects and influence subsequent computation.
What do variables denote in the context of l-value and r-value?
l-value denotes a location in memory, while r-value denotes a value.
What is the difference between value and reference models in language design?
Value model directly manipulates values (Pascal, C, C++), while reference model variables refer to values (CLU, Java).
What is orthogonality in the context of programming languages?
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.
What are the benefits of variable initialization and which languages provide it?
Initialization prevents errors and allows static allocation. Pascal does not provide it by default, while C, C++, and Ada support initialization of aggregates.
How do different languages handle uninitialized variables?
Pascal guarantees default values. C guarantees zero values only for static variables, while others may contain garbage values.