Skip to main content

Section 2.13 Assessment: Operation Precedence

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: Given the following, what value is stored in variable alpha?
    int alpha = 0;
    int x = 5;
    int y = 6;
    int z = 2;
    alpha = x + y * z - 1;
    

    2.

    Q2: Given the following, what value is stored in variable beta?
    int beta = 0;
    int x = 5;
    int y = 6;
    int z = 2;
    beta = (y + 3) * (x / 3) - z;
    

    3.

    Q3: Given the following, what value is stored in variable gamma?
    int x = 5;
    int y = 6;
    double gamma = 1.0;
    

    4.

    Q4: Given the following, what value is stored in variable delta?
    int delta = 0;
    int x = 5;
    int y = 6;
    int z = 2;
    delta = x % y * z % y;
    

    5.

      Q5: Given the following, do iota and zeta contain the same value?
      int eta = 5;
      int iota = (eta + 5) * (5 % eta + 2);
      int zeta = eta + 5 * (5 % eta + 2);
      
    • Yes
    • Incorrect
    • No
    • Correct
You have attempted of activities on this page.