teach-ict.com logo

THE education site for computer science and ICT

3. Arithmetic operators

You are already familiar with many simple arithmetic operations: addition, subtraction, division and multiplication. The symbols used to represent these operations in a program are mostly the same ones you see in a maths textbook:-

+ for addition

- for subtraction

* for multiplication

/ for division

Arithmetic operators have two arguments, one on either side. Their position matters most for things like subtraction and division. 100/2 is very different from 2/100.

A slightly less common operation is exponentiation, which means raising a number up to the power of another number (like squaring or cubing). The operator symbol for this usually ^ or sometimes EXP

You can use multiple arithmetic operators on the same line, if you need to perform a complex calculation. The order that you carry out these calculations, called the 'order of operations' is BODMAS. This stands for

  • Brackets first
  • Order (numbers involving powers or square roots)
  • Division
  • Multiplication
  • Addition
  • Subtraction

This lets you work out expressions such as

        x  1 + ( 3 - 1) - 2^3 + 10/3 

in the same correct order.