Appendix C. Order of Operations

When mathematical calculations are performed in a program, each operation takes place according to a prespecified order. This order of operations ensures that the code is run the same way every time. This is no different from arithmetic or algebra, but programming has other operators that are less familiar.

In the following table, the operators on the top are run before those below. Therefore, an operation inside parentheses will run first and an assignment will run last.

Name

Symbol

Examples

Parentheses

()

a * (b + c)

Postfix, Unary

++ −− !

a++ −−b !c

Multiplicative

* / %

a * b

Additive

+ −

a + b

Relational

> < <= >=

if (a > b)

Equality

== !=

if (a == b)

Logical AND

&&

if (mousePressed && (a > b))

Logical OR

||

if (mousePressed || (a > b))

Assignment

= += −= *= /= %=

a = 44

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.216.77.153