Arithmetic Expressions (College Board AP® Computer Science Principles): Revision Note

Robert Hampton

Written by: Robert Hampton

Reviewed by: James Woodhouse

Updated on

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

7 + 3

10

-

Subtraction

Subtracts the second value from the first

7 - 3

4

*

Multiplication

Multiplies two values

7 * 3

21

/

Division

Divides the first value by the second

7 / 2

3.5

MOD

Modulus

Returns the remainder after division

7 MOD 3

1

The modulus operator

  • The modulus operator (MOD) is frequently used in programming to determine the remainder of a division

  • Common uses include:

    • Checking if a number is even or odd (n MOD 2 returns 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:

    1. Parentheses (evaluated first, override all other rules)

    2. Multiplication, division, and MOD (evaluated left to right)

    3. 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 b returns the remainder when a is divided by b. 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!

Join the 100,000+ Students that ❤️ Save My Exams

the (exam) results speak for themselves:

Robert Hampton

Author: Robert Hampton

Expertise: Computer Science Content Creator

Rob has over 16 years' experience teaching Computer Science and ICT at KS3 & GCSE levels. Rob has demonstrated strong leadership as Head of Department since 2012 and previously supported teacher development as a Specialist Leader of Education, empowering departments to excel in Computer Science. Beyond his tech expertise, Robert embraces the virtual world as an avid gamer, conquering digital battlefields when he's not coding.

James Woodhouse

Reviewer: James Woodhouse

Expertise: Computer Science & English Subject Lead

James graduated from the University of Sunderland with a degree in ICT and Computing education. He has over 14 years of experience both teaching and leading in Computer Science, specialising in teaching GCSE and A-level. James has held various leadership roles, including Head of Computer Science and coordinator positions for Key Stage 3 and Key Stage 4. James has a keen interest in networking security and technologies aimed at preventing security breaches.