Integers

This lesson explains fundamental arithmetic operations in general and provides background knowledge related to the integer data type.

Arithmetic operations #

The basic arithmetic operations are addition, multiplication, division and subtraction. Arithmetic operations allow us to write much more useful programs.

Arithmetic operations
Arithmetic operations

Before going further, let’s have a look at the summary of arithmetic operations:

Summary of arithmetic operations/operators
Summary of arithmetic operations/operators

Most of those operators have counterparts that have an = sign attached: +=, -=, *=, /=, %=, and ^^=. These operators assign the result of the operation to the variable on the left-hand side.

variable += 10;

This expression adds 10 to the value of the variable and assigns the result to variable. After the operation, the value of the variable would be incremented by 10. It is the equivalent of the following expression:

variable = variable + 10;

Although arithmetic operations are a part ...