## Section1.31Assessment: Swap

### Subsection1.31.1Subgoals for evaluating an assignment statement

1. Determine resultant data type of expression

2. Update variable for pre-increment or pre-decrement operators (side effect)

3. Evaluate arithmetic expression according to operator precedence

4. If an assignment statement (=), is Left Hand Side (LHS) a variable? Check data type of value against data type of variable.

5. Update variable for post-increment or post-decrement operators (side effect)

### Exercises1.31.2Exercises

#### 1.

Q1: After executing the following code, the value in variable a is and the value in variable b is .

#### 2.

Q2: After executing the following code, the value in variable r is and the value in variable s is .

#### 3.

Q3: After executing the following code, the value in variable p is and the value in variable q is .

#### 4.

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 .

#### 5.

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.

• d = temp; b = a;

• d = c; b = a;

• d = c; b = temp;

• d = a; b = temp;

• d = a; b = c;