AP® Computer Science Principles · Big Idea 3 · Topic 3.3

Arithmetic Operators and Order of Operations

Order of operations is the fixed ranking that decides which part of an expression a program computes first: parentheses, then multiplication and division, then addition and subtraction.

A program does not read an arithmetic expression the way you read a sentence, left to right. It ranks the operators first and does the highest-ranked ones first, wherever they sit. Parentheses win every time. After that, multiplication and division outrank addition and subtraction. When operators tie in rank, like a division next to a multiplication, the program works left to right between just those two.

Mechanically, evaluation collapses the expression step by step until one number is left. Take 7 + 3 x 4 - 10 / 5. The program scans for the highest-ranked operations: 3 x 4 becomes 12, and 10 / 5 becomes 2. The expression is now 7 + 12 - 2. Only addition and subtraction remain, so it finishes left to right: 7 + 12 is 19, then 19 - 2 is 17. Parentheses override all of this by forcing a sub-expression to resolve first, as in (14 - 2) / 4 + 3 x 2: the parentheses give 12, so the expression becomes 12 / 4 + 3 x 2, then 3 + 6, then 9.

This topic matters because every variable assignment and every condition in a branch or loop relies on an expression being evaluated the same way every time. If order of operations were ambiguous, the same line of code could produce different values on different runs, which would break the predictability that algorithms depend on. Later, when expressions mix arithmetic with comparisons like greater-than or boolean operators like AND, the same idea of ranked evaluation extends to decide what resolves first.

Key terms

Order of operations
The fixed ranking that decides which operators in an expression are evaluated first.
Operator precedence
The rank given to an operator, such as multiplication outranking addition.
Expression
A combination of values and operators that a program reduces to a single value.
Evaluation
The process of collapsing an expression step by step until one value remains.

Watch it explained

  1. How it worksHow does a program evaluate an expression from the inside out down to a single value?
  2. Worked exampleFind the value of 7 + 3·4 - 10 / 5 by following the order of operations.
  3. Worked exampleFind the value of (14 - 2) / 4 + 3·2.
  4. Common mistakeWhy doesn't a program read an arithmetic expression strictly from left to right?

Check yourself

Your turn1 of 2
Find the value of 14 + 7·9 - 32 / 3 using standard order of operations.

End of topic.