O'Reilly logo

Mastering Swift 4 - Fourth Edition by Jon Hoffman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Arithmetic operators

The arithmetic operators perform the four basic mathematical operations.

Here are some prototypes:

Addition:   
  varA + varB 
Subtraction:   
  varA - varB 
Multiplication:   
  varA * varB 
Division:   
  varA / varB 

Here are some examples:

var x = 4 + 2 //x will equal 6  
var x = 4 - 2 //x will equal 2  
var x = 4 * 2 //x will equal 8  
var x = 4 / 2 //x will equal 2 
var x = "Hello " + "world"  //x will equal "Hello World" 

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required