Tsallaka zuwa abun ciki
Justice Tech School

inout Parameters

inout lets a function change the caller variable. Pass with &.

Example
func double(_ n: inout Int) { n *= 2 }
var x = 5
double(&x)
print(x)

Exercise

Pass by reference.

double(x)

Quiz Test

What does inout need at the call?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.