Arithmetic Expressions
- +,- as expected
- * is multiply
- / is strange
- For float types it is fine.
- For integers it is integer division.
- The other part of integer division is % (modulus)
- This is the remainder part.
- 5 % 3 = 2
- 4 % 7 = 4
- This is more useful than you would think.
- Some strange ones
- We do
i = i + 1
so often they gave us two short cuts
- We do things like
i = i * n
frequently so they gave us
-
triple *= 3;
-
luck += 7;
-
age /= 15;
-
months %= 9;
- Look at appendix B, operator precedence.
- Please Excuse My Dear Aunt Sally applies
- () work just fine.