Skip to main content

Section 2.22 Assessment: Pre/Post Operators

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 a = 0;
    int b = 1;
    int c = 2;
    int d = 3;
    int alpha;
    alpha = ++a + b--;
    

    2.

    Q2: Given the following, what value is stored in variable beta?
    int a = 0;
    int b = 1;
    int c = 2;
    int d = 3;
    int alpha;
    int beta;
    alpha = c-- * ++b;
    beta = alpha - d++ + b * a;
    

    3.

    Q3: Given the following, what value is stored in variable gamma?
    int a = 0;
    int b = 1;
    int c = 2;
    int gamma;
    gamma = ++a + ++b + c--;
    

    4.

      Q4: Given the following, what value is stored in variable delta?
      int a = 0;
      int b = 1;
      int c = 2; 
      int d = 3; 
      int delta;
      delta = d / --c - a % ++b;
      
    • 3
    • 2
    • 1
    • 0

    5.

      Q5: Which of the following are syntactically valid ways to increment the value of eta by one? Select all that apply.
    • eta++;
    • eta + 1;
    • ++eta;
    • eta += 1;
    • eta = eta + 1;
You have attempted of activities on this page.