1.14.2. Assessment: SwapΒΆ
Subgoals for evaluating an assignment statement
Determine resultant data type of expression
Update variable for pre-increment or pre-decrement operators (side effect)
Evaluate arithmetic expression according to operator precedence
If an assignment statement (=), is Left Hand Side (LHS) a variable? Check data type of value against data type of variable.
Update variable for post-increment or post-decrement operators (side effect)
- d = temp; b = a;
- d = c; b = a;
- d = c; b = temp;
- d = a; b = temp;
- d = a; b = c;
Q1: After executing the following code, the value in variable a
is and the value in variable b
is .
int a = 1;
int b = 2;
a = 3;
Q2: After executing the following code, the value in variable r
is and the value in variable s
is .
int r = 2;
int s = 4;
r = s;
Q3: After executing the following code, the value in variable p
is and the value in variable q
is .
int p = 1;
int q = 8;
q = p;
p = q;
Q4: After executing the following code, the value in variable x
is , the value in variable y
is , and the value in variable z
is .
int x = 7;
int y = 5;
int z = 3;
x = y;
y = z;
z = x;
Q5: Suppose there are four integer
variables a
, b
, c
, and d
as depicted below. The code beside the diagram is intended to move the values in those variables one place clockwise, but two statements are missing. Choose the option that has the correct 2 statements.
