Swift Operator Precedence And Associativity



Swift Programming Language By Knownion


Precedence And Associativity


Operator precedence is a set of rules that determines which operator is executed first.

Before you learn about operator precedence, make sure to know about Swift operators.

Let's take an example, suppose there is more than one operator in an expression.

var num = 8 + 5 * 4 // 28

Here,
if + is executed first, the value of num will be 52
if * is executed first, the value of num will be 28

In this case, operator precedence is used to identify which operator is executed first. The operator precedence of * is higher than + so multiplication is executed first.



Post a Comment