Arithmetic Expressions (College Board AP® Computer Science Principles): Revision Note
Arithmetic operations
What arithmetic operations are available in programs?
Arithmetic operators perform standard arithmetic calculations on numeric values
AP CSP pseudocode supports five core arithmetic operations
Operator | Name | Description | Example | Result |
|---|---|---|---|---|
| Addition | Adds two values |
|
|
| Subtraction | Subtracts the second value from the first |
|
|
| Multiplication | Multiplies two values |
|
|
| Division | Divides the first value by the second |
|
|
| Modulus | Returns the remainder after division |
|
|
The modulus operator
The modulus operator (
MOD) is frequently used in programming to determine the remainder of a divisionCommon uses include:
Checking if a number is even or odd (
n MOD 2returns 0 for even numbers)Cycling through a fixed range of values (e.g. clock arithmetic)
Extracting individual digits from a number
Mathematical precedence
What is the order of operations?
Precedence determines the order of operations when an expression contains multiple operators
Operations with higher precedence are evaluated first
The standard order is:
Parentheses (evaluated first, override all other rules)
Multiplication, division, and MOD (evaluated left to right)
Addition and subtraction (evaluated left to right)
When operators have equal precedence, they are evaluated left to right
result ← 3 + 4 * 2
This evaluates to
11(multiplication first: 4 * 2 = 8, then addition: 3 + 8 = 11)
result ← (3 + 4) * 2
This evaluates to
14(parentheses first: 3 + 4 = 7, then multiplication: 7 * 2 = 14)
Examiner Tips and Tricks
MOD is one of the most commonly tested operators on the AP exam. Know that
a MOD breturns the remainder whenais divided byb. If an expression contains multiple operators without parentheses, always apply precedence rules — do not evaluate left to right by default. When in doubt, work through the expression step by step and show your reasoning.For the AP Create Performance Task, if your program performs calculations, be prepared to explain on exam day what arithmetic operations your program uses and how they contribute to your program's output — pay particular attention to any use of MOD or expressions involving multiple operators
Worked Example
What is the result of the following expression?
17 MOD 5 + 3 * 2
(A) 4
(B) 8
(C) 10
(D) 14
[1]
Answer:
(B) 8 [1 mark]
MOD and multiplication share equal precedence and evaluate left to right: 17 MOD 5 = 2, then 3 × 2 = 6, giving 2 + 6 = 8
Unlock more, it's free!
Was this revision note helpful?