Worksheet W.A.4.1 Name ___________________________
precedence and assignment operators
Using precedence rules, determine the correct answer to the following expressions:
1. 8 + 3 * 6 / 5 % 6 - 9 5. 12 * 3 % 8 / 2
2. (8 * 3) / 9 + 2 * 5 6. (12 * 3) % (8 / 2)
3. (double) 9 / 4 7. 17.5 / 3.75 + 2
4. (int) 17.5 / 3 8. 12.5 % 3
9. Explain how this statement is evaluated: a = b = 2;
Translate each of the following statements into C++ code. Where appropriate, several versions will be requested:
10. Increment number by 10. (2 versions)
a. longer version b. using assignment operator
11. Increment count by 1. (2 versions)
a. longer version b. using increment operator
12. Multiply base by 2. (2 versions)
a. longer version b. using assignment operator
Determine the result of the following fragments of code:
13. final value of a & b 14. final value of a & b
b = 2; b = 2;
a = ++b; a = b++;
15. What is the most important reason for using constants in a program?