SwiftQuiz
#1

Tuple Element Swap

  • tuples
  • exclusivity
  • ownership
Swift 6.3.2 Report an issue

Verified quizzes have their expected answer checked by compiling and running the code with the listed Swift toolchain during the site build.

func swaps(_ a: inout Int, _ b: inout Int) {
    let temp = a
    a = b
    b = temp
}

var t = (1, 2)
swaps(&t.0, &t.1)

print(t.0)
print(t.1)
Hint

What does Swift's law of exclusivity say about two inout arguments derived from the same root variable?

Your answer

What does this program do?