7.3 Operators, Precedence, Expressions, and Formulas

Key Takeaways

  • The standard operator groups are assignment (←), arithmetic (+ − * / % ^), relational (== < > ≤ ≥ ≠), and logical (and, or, not).
  • Multiplication, division, and remainder are evaluated before addition and subtraction, left to right within each level; parentheses override everything.
  • A formula's fractions need parentheses: the average of a and b is ( a + b ) / 2, not a + b / 2.
  • With integer division, 1 / 2 * base * height is 0; write 0.5 * base * height or base * height / 2.0 instead.
  • With integers, n % 10 gives the last digit, n / 10 removes the last digit, and n % 2 == 0 tests for an even number.
Last updated: September 2026

What this competency asks

ETS asks you to understand how to use standard operators (assignment, arithmetic, relational, logical) and operator precedence to write programs. The listed skills include tracing code, finding missing code, identifying equivalent statements, putting statements in order, using Boolean algebra (Section 7.4), and two skills specific to this topic:

  • Identify the correct implementation of a given formula, including formulas with fractions.
  • Evaluate expressions that include arithmetic operations.

The four operator families

FamilyETS symbolsProducesExample
Assignment←Stores a valuex ← x + 1
Arithmetic+ - * / % ^A numbertotal * 2, n % 2
Relational== < > ≤ ≥ ≠true or falsescore ≥ 70
Logicaland or nottrue or false( age ≥ 13 ) and ( age < 18 )

+ is also string concatenation when a string is involved. ^ appears in ETS's list of arithmetic operators, where it conventionally means exponentiation. In Java and C, however, ^ means bitwise XOR, which is one more reason to read the notation you are given.

Precedence

ETS does not publish a precedence table for its pseudocode, and its code usually parenthesizes conditions fully. When parentheses are missing, the conventional order is:

PriorityOperatorsGrouping
1 (highest)Parentheses ( )Innermost first
2Unary minus, not—
3^ (exponentiation, where supported)—
4* / %Left to right
5+ -Left to right
6< > ≤ ≥—
7== ≠—
8and—
9or—
10 (lowest)←The right side is evaluated first

Languages differ in the details. In Python, for example, not binds more loosely than comparisons. When in doubt, add parentheses to your own code and look for them in ETS code.

Worked evaluation (all values int; / is integer division)

14 + 6 / 2 * 3 - 5 % 2

  1. *, /, and % first, left to right: 6 / 2 = 3, then 3 * 3 = 9, and separately 5 % 2 = 1.
  2. The expression is now 14 + 9 − 1.
  3. + and - left to right: 23 − 1 = 22.

19 / 4 + 19 % 4 * 3: 19 / 4 = 4; 19 % 4 = 3, then 3 × 3 = 9; 4 + 9 = 13.

The remainder operator in practice

GoalExpressionExample (n = 4726)
Test for even or oddn % 2 == 04726 % 2 = 0, so even
Last digitn % 106
Drop the last digitn / 10 (integer)472
Wrap an index around a circle of size k( i + 1 ) % kIndex 4 with k = 5 wraps to 0
Every third itemi % 3 == 0Items 0, 3, 6, …
Minutes to hours and minutesm / 60 and m % 60125 minutes gives 2 hours and 5 minutes

A digit-summing loop combines the last two rows: repeatedly add n % 10 to a total, then set n ← n / 10, until n is 0.

Implementing formulas with fractions

Written math hides grouping that code must make explicit.

FormulaCorrectWrong (why)
Average of a and b( a + b ) / 2a + b / 2: only b is halved
Slope between two points( y2 - y1 ) / ( x2 - x1 )y2 - y1 / x2 - x1: division happens first
Quadratic root( -b + sqrt ( b * b - 4 * a * c ) ) / ( 2 * a )… / 2 * a divides by 2 and then multiplies by a
Triangle area0.5 * base * height or base * height / 2.01 / 2 * base * height: with integers, 1 / 2 is 0
Celsius to Fahrenheit9.0 / 5 * c + 329 / 5 * c + 32 with integers: 9 / 5 is 1, so the result is c + 32

Two habits prevent most errors:

  1. Wrap every numerator and every denominator that contains more than one term in parentheses.
  2. Check the types. If every operand is an integer and the formula needs a fraction, make one operand floating-point (write 2.0, or convert a variable first). Order matters too: with integers, c * 9 / 5 is closer to correct than 9 / 5 * c, because the multiplication happens before the truncating division. It still truncates the result, though, since 37 * 9 / 5 = 333 / 5 = 66.

Equivalent statements

Some rewrites are always equivalent, and some are only equivalent with real-number arithmetic.

PairEquivalent?
x ← x + 1 and x ← 1 + xYes
total ← total * 2 and total ← total + totalYes
( a + b ) / 2 and a / 2 + b / 2 (integers)No. a = 3, b = 5 gives 4 versus 1 + 2 = 3
a * ( b + c ) and a * b + a * cYes (the distributive property holds for integers)
( x > 5 ) and not ( x ≤ 5 )Yes
x / 2 * 2 == x for every integer xNo. It is true only when x is even

When asked whether two segments are equivalent, test boundary values, such as odd numbers, 0, and negative numbers, rather than just one convenient case.

Assignment versus equality

x ← 5 changes x. x == 5 asks whether x equals 5. In languages such as C and Java, = is assignment. Writing if (x = 5) is a classic bug: in C it assigns 5 and treats the condition as true, and in Java it fails to compile for an int x.

Putting statements in order

Many questions show the right statements in the wrong order. For example, to swap the values of a and b, you need a temporary variable, and the order matters:

int temp ← a
a ← b
b ← temp

Writing a ← b first would destroy a's original value before it was saved. Tracing with concrete values, such as a = 1 and b = 2, confirms the order.

Test Your Knowledge

All variables are int, and / performs integer division on int values. What is stored in result?

int x ← 19
int y ← 4
int z ← 3
int result ← x / y + x % y * z

A
B
C
D
Test Your Knowledge

base and height are int variables, and / performs integer division when both operands are int. Which expression correctly computes the area of a triangle, one-half times base times height, for all values?

A
B
C
D
Test Your Knowledge

Let a ← 3 and b ← 5, both int, with / performing integer division. Which expression's value is different from the value of ( a + b ) / 2?

A
B
C
D