Order of operations
For example, in the expression "five added to six multiplied by seven," the operators are addition and multiplication (five, six, and seven are the operands). If the addition is performed first, the result is 77, but if multiplication is performed first, the result is 47. Order of operations dictates that the correct answer is 47 because multiplication and division must always be performed before addition and subtraction.
Mathematical order of operations
- Parentheses, exponents and roots; then
- Multiplication and division; and then
- Addition and subtraction.
Tip: An easy way to remember the order of operations is PEMDAS, or "Please Excuse My Dear Aunt Sally."
In computer programming, most languages use precedence levels that are the same as science and mathematics. Some languages, such as Smalltalk and Lisp, have no precedence rules at all: the programmer must specify the operators in the correct order.
In the C programming language, the following levels of operator precedence apply, listed here in order of decreasing precedence:
|Level 1 (highest precedence)|
|( )||Function call|
|[ ]||Array subscripting|
|.||Element selection by reference|
|->||Element selection through pointer|
|<<||Bitwise shift left|
|>>||Bitwise shift right|
|<=||Less than or equal|
|>=||Greater than or equal|
|^||Bitwise XOR (exclusive or)|
||||Bitwise OR (inclusive or)|
|+=||Assignment by sum|
|-=||Assignment by difference|
|*=||Assignment by product|
|/=||Assignment by quotient|
|%=||Assignment by remainder|
|<<=||Assignment by bitwise left shift|
|>>=||Assignment by bitwise right shift|
|&=||Assignment by bitwise AND|
|^=||Assignment by bitwise XOR|
||=||Assignment by bitwise OR|