1.9. Assessment: Pre/Post OperatorsΒΆ
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)
- 1.5
- 2.5
- 1
- 2
- Compiler error - will not compile
- eta++;
- eta + 1;
- ++eta;
- ++eta--;
- eta = eta + 1;
Q1: Given the following, what value is stored in variable alpha?
int a = 0, b = 1, c = 2, d = 3, alpha;
alpha = ++a + b--
Q2: Given the following, what value is stored in variable beta?
int a = 0, b = 1, c = 2, d = 3;
int alpha, beta;
alpha = c-- * ++b;
beta = alpha - d++ + b * a;
Q3: Given the following, what value is stored in variable gamma?
int a = 0, b = 1, c = 2, d = 3;
int gamma;
gamma = ++a + ++b + c--;
Q4: Given the following, what value is stored in variable detla?
int a = 0, b = 1, c = 2, d = 3, delta;
delta = (d / c)++ - (a % ++b);
Q5: Which of the following are syntactically valid ways to increment the value of eta
by one? Select all that apply.