Swift: Operators and Operands

Operator is a special symbol or phrase that can check, combine or change the values. Swift provides us with operators with functionalities similar to the one in most popular programming languages in addition to overflow operators and advanced operators. Advanced operators allows us to define our own custom operator types and implement the standard operators in our own custom type.

In general there are three kinds of operators in Swift.

  1. Unary operator : Unary operator operates on a single target value.They appear as postfix or prefix operator.
  2. Binary operator : Binary operator operates on two target values and are called infix operators as they appear in between the two target values.
  3. Ternary operator : Ternary operator operates on three target values. There is only one ternary operator in Swift.

Operands are the values affected by the operators.

Swift code:

Output:

 

 

 

Leave a Reply