Skip to main content

Section 2.31 Assessment: Swap

Subgoals for evaluating an assignment statement.

  1. Determine resultant data type of expression
  2. Update variable for pre operators based on side effect
  3. Solve arithmetic equation, operator precedence
  4. Is the Left Hand Side (LHS) of the assignment statement a variable? Check the data type of the value on right hand side (RHS) against data type of LHS variable.
  5. Update variable for post operators based on side effect

Exercises Exercises

    1.

    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;
    

    2.

    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;
    

    3.

    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;
    

    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 .
    int x = 7;
    int y = 5;
    int z = 3;
    x = y;
    y = z;
    z = x;
    

    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.
      Figure 2.31.1.
    • d = temp; b = a;
    • d = c; b = a;
    • d = c; b = temp;
    • d = a; b = temp;
    • d = a; b = c;
You have attempted of activities on this page.