Course contentsShow
← Computer Science
Lesson 154 of 2,8724. Introduction to ProgrammingFree lesson

Arithmetic Operators

Learn addition, subtraction, multiplication, division, and modulo operators for numeric computation.

Arithmetic Operators

What you'll learn: How to use basic math operators to perform calculations with numbers in code.

What Are Arithmetic Operators?

Arithmetic operators are symbols that tell the computer to perform mathematical calculations on numeric values (integers and floating-point numbers). They're the building blocks for any computation in your programs—from simple addition to complex formulas.

The Five Core Operators

Just like in mathematics, programming languages provide operators for basic arithmetic:

  • Addition (+): Adds two numbers together

    • Example: 5 + 3 evaluates to 8
  • Subtraction (-): Subtracts the second number from the first

    • Example: 10 - 4 evaluates to 6
  • Multiplication (*): Multiplies two numbers

    • Example: 7 * 6 evaluates to 42
  • Division (/): Divides the first number by the second

    • Example: 20 / 4 evaluates to 5
  • Modulo (%): Returns the remainder after division

    • Example: 17 % 5 evaluates to 2 (because 17 ÷ 5 = 3 remainder 2)

Using Operators in Expressions

Remember that expressions (which you just learned about) combine values and operators. Arithmetic operators are what make numeric expressions powerful:

totalCost = price * quantity
remainder = minutes % 60
average = (score1 + score2 + score3) / 3

Each operator takes two operands (the values on either side) and produces a result that becomes part of the expression's final value.

Key Takeaway: Arithmetic operators (+, -, *, /, %) let you perform mathematical calculations on numeric data, turning your variables and values into useful computed results.