August 2001
Beginner
482 pages
10h 52m
English
In the complex statement
x = 5 + 3 * 8;
which is performed first, the addition or the multiplication? If the addition is performed first, the answer is 8 * 8, or 64. If the multiplication is performed first, the answer is 5 + 24, or 29.
Every operator has a precedence value, and the complete list is conveniently located on the tear card at the front of the book. Multiplication has higher precedence than addition, and thus the value of the expression is 29. |
When two mathematical operators have the same precedence, they are performed in left-to-right order. Thus
x = 5 + 3 + 8 * 9 + 6 * 4;
is evaluated multiplication first, left to ...
Read now
Unlock full access