Recall & Review
beginner
What is an in-out parameter in Swift?
An in-out parameter allows a function to modify a variable passed to it, so the changes persist outside the function.
Click to reveal answer
beginner
How do you declare an in-out parameter in a Swift function?
Use the
inout keyword before the parameter type in the function definition.Click to reveal answer
beginner
How do you pass a variable as an in-out argument when calling a Swift function?
Use the ampersand
& before the variable name to pass it as an in-out argument.Click to reveal answer
intermediate
Why can't you pass a constant or a literal as an in-out argument?
Because in-out parameters require the ability to modify the variable, constants and literals cannot be changed.
Click to reveal answer
beginner
What happens if you forget to use
& when passing an in-out argument?The Swift compiler will give an error because it expects an explicit indication that the variable can be modified.
Click to reveal answer
Which keyword is used to declare an in-out parameter in Swift?
✗ Incorrect
The
inout keyword marks a parameter that can be modified inside the function.How do you pass a variable as an in-out argument when calling a function?
✗ Incorrect
You must use
& before the variable name to indicate it can be modified.Can you pass a constant as an in-out argument?
✗ Incorrect
Constants cannot be passed as in-out arguments because they cannot be changed.
What is the main purpose of in-out parameters?
✗ Incorrect
In-out parameters let functions change the original variable passed in.
What error occurs if you forget the & when passing an in-out argument?
✗ Incorrect
Swift compiler requires the & to clearly show the variable can be modified.
Explain how in-out parameters work in Swift and why they are useful.
Think about how a function can change a variable outside its own scope.
You got /4 concepts.
Describe the syntax for declaring and using an in-out parameter in a Swift function.
Focus on the keywords and symbols needed.
You got /3 concepts.