1.5. Assessment: Operation PrecedenceΒΆ
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)
Q1: Given the following, what value is stored in variable alpha?
int alpha = 0, x = 5, y = 6, z = 2;
alpha = x + y * z - 1
Q2: Given the following, what value is stored in variable beta?
int beta = 0, x = 5, y = 6, z = 2;
beta = (y + 3) * (x / 3) - z;
Q3: Given the following, what value is stored in variable gamma?
int x = 5, y = 6;
double gamma = 1.0;
gamma = gamma * -1.0 + x / y;
Q4: Given the following, what value is stored in variable delta?
int delta = 0, x = 5, y = 6, z = 2;
delta = x % y * z % y;
Q5: Given the following, if iota
contains the value 32, what must be the value stored in variable eta
?
int eta = ??;
int iota = (eta + 5) * (5 % eta + 2);