This section contains 769 words (approx. 3 pages at 300 words per page) |
In school, while learning basic arithmetic, students are also taught precedence rules for the various arithmetic operators. This is often done using a mnemonic such as "My Dear Aunt Sally" (denoting the order as Multiplication, Division, Addition, and Subtraction). Therefore, given an expression 2 + 3 x 4 - 1, we know that the multiplication should be evaluated first, followed by the addition and finally the subtraction--the answer thus is 12 + 2 - 1, or 13.
This order of operator precedence is also important in programming, because expressions should be evaluated by the compiler in the same way that the programmer intended them to be. This happens only when the programmer who writes the code, and the compiler writer who determines how program statements are translated into machine code, have the same notation in mind. In most programming languages in use today, the notation in use is as described above, and both compiler...
This section contains 769 words (approx. 3 pages at 300 words per page) |