Section 2.4 Basic Knowledge
Subgoals for evaluating an assignment statement.
Subsection 2.4.1
Given the following code snippet, evaluate the final statement (the last line). If invalid, give the reason. If valid, what value is assigned to the variable?
alpha = 2
beta = 3.0
delta = 3
gamma = alpha + delta
Subsection 2.4.2 SG1: Decide order of operations
There is only one operator (an addition
+
) so that will be evaluated first.
Subsection 2.4.3 SG2: Determine operator behavior based on operands
The expression
alpha + delta
is an addition between two integer values. This is a valid operation, and will produce an integer.
Subsection 2.4.4 SG3: Solve arithmetic, expression, or operation
The variable
alpha
is substituted for the value 2
and the variable delta
is substituted for the value 3
. Adding them together produces the value 5
. This value is stored in gamma
.
Subsection 2.4.5 Questions to check understanding
-
Is the left-hand-side (LHS) of the statement a variable? What type?
-
What is the resulting type after evaluating the right-hand-side (RHS)?
-
Answer.
You have attempted 1 of 1 activities on this page.