Select Page

Crazy Level

Swift and Xcode Resources.

Reversing the values of numbers using Variables
Published on: February 18, 2021
Author: Frank Vernon

Example code:

var a = 5
var b = 8

print(“a: \(a)”)
print(“b: \(b)”)

// To make the values of “a” and “b” reversed, see the code below. //

var c = a
a = b
b = c

print(“a: \(a)”)
print(“b: \(b)”)

The printed value is:
a: 5
b: 8
a: 8
b: 5