Examples · learn/11-values · 171 of 339
inout
tin run examples/learn/11-values/inout.tintype Robot = { name: string, battery: int }
// inout: this function may change the caller's variable.
fn charge(r: inout Robot, amount: int) {
r.battery = min(100, r.battery + amount)
}
fn main() {
var bud = Robot { name: "Bud", battery: 70 }
charge(&bud, 20) // & at the call: you can see that bud may change here
print(bud)
charge(&bud, 20)
print(bud)
}