# Order of operations

**Order of operations**, also called operator precedence, is a set of rules specifying which procedures should be performed first in a mathematical expression.

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.
- Multiplication and division.
- Addition and subtraction.

An easy way to remember the order of operations is PEMDAS, or "Please Excuse My Dear Aunt Sally."

## Computer programing

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) | |
---|---|

operator: |
operation: |

++ |
Increment |

-- |
Decrement |

( ) |
Function call |

[ ] |
Array subscripting |

. |
Element selection by reference |

-> |
Element selection through pointer |

Level 2 | |

* |
Multiplication |

/ |
Division |

% |
Modulo |

Level 3 | |

+ |
Addition |

- |
Subtraction |

Level 4 | |

<< |
Bitwise shift left |

>> |
Bitwise shift right |

Level 5 | |

< |
Less than |

<= |
Less than or equal |

> |
Greater than |

>= |
Greater than or equal |

Level 6 | |

== |
Equal |

!= |
Not equal |

Level 7 | |

& |
Bitwise AND |

Level 8 | |

^ |
Bitwise XOR (exclusive or) |

Level 9 | |

| |
Bitwise OR (inclusive or) |

Level 10 | |

&& |
Logical AND |

Level 11 | |

|| |
Logical OR |

Level 12 | |

?: |
Ternary conditional |

Level 13 | |

= |
Direct assignment |

+= |
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 |

Level 14 | |

, |
comma |