Complete the code to declare an in-out parameter in the function.
func increment(number: [1] Int) { number += 1 }
In Swift, inout is used to allow a function to modify a parameter's value.
Complete the code to call the function with an in-out parameter correctly.
var value = 5 increment([1]value)
When passing an in-out parameter, you must prefix the variable with & to indicate it can be modified.
Fix the error in the function call by completing the blank.
func doubleValue(number: inout Int) {
number *= 2
}
var num = 10
doubleValue(number: [1]num)The & symbol is required before the variable name when passing it as an in-out parameter.
Fill both blanks to create a function that swaps two integers using in-out parameters.
func swapInts(a: [1] Int, b: [2] Int) { let temp = a a = b b = temp }
Both parameters must be declared as inout to allow swapping their values.
Fill all three blanks to create a function that increments a number by a given amount using in-out parameters.
func incrementBy(amount: [1] Int, number: [2] Int) { number [3]= amount }
The amount is a constant input (let), number is an inout parameter to be modified, and += adds the amount to number.