**Introduction**

This is part six of "Swift Programming - Zero to Hero" series. In this article, we will be learning about Arithmetic Operators. Before you continue in this session, please follow the previous series.

**Arithmetic Operators**

Almost all the computer programs do arithmetic operations, such as addition, subtraction, multiplication, and division. There are five arithmetic operators, plus(+), minus (-), multiplication (*), division (/), and modulus (%) used in Swift. The plus (+) sign is used for addition, a minus (-) sign is used for subtraction, asterisk (*) is used for multiplication, forward slash (/) is used for division, and modulus (%) is used to return the remainder. Let's see an example code snippet for Arithmetic Operations,

*Addition*

- 10+25=35

*Subtraction*

- 20-10=10

- 6*5=30

- 10/5=2

Modulus

- 7%5=2

- 5+3*2

In an assignment statement, the multiplication and division operations are performed first; then, modulus operations, and finally, the addition and subtraction operations. So, the answer to the preceding example would be 11 instead of 1, since the multiplication has been done before the addition.

If the precedence level of the two operators is same, the operations are performed from left to right, as shown in the following example.

- 20/2*5

- 20/(2*5)

- ((2+3)*5)+7

**Conclusion**

In this article, we have learned about Arithmetic Operators. Hope it was useful. We will learn more concepts in Swift programming in upcoming articles.

Up Next

Ebook Download

View all
Learn

View all