Bird
0
0

Given the function:

hard📝 Application Q15 of 15
Swift - Functions
Given the function:
func update(user name: String, age years: Int) {
    print("User: \(name), Age: \(years)")
}

Which is the correct way to call this function to print User: John, Age: 30?
Aupdate(user: "John", age: 30)
Bupdate(name: "John", years: 30)
Cupdate(user name: "John", age years: 30)
Dupdate("John", 30)
Step-by-Step Solution
Solution:
  1. Step 1: Identify argument labels and parameter names

    The function has argument labels user and age, with parameter names name and years.
  2. Step 2: Match call syntax

    The call must use argument labels: update(user: "John", age: 30) is correct.
  3. Final Answer:

    update(user: "John", age: 30) -> Option A
  4. Quick Check:

    Call uses argument labels, function uses parameter names inside [OK]
Quick Trick: Use argument labels in call, parameter names inside function [OK]
Common Mistakes:
  • Using parameter names instead of argument labels in call
  • Trying to call with both labels and names together
  • Omitting argument labels entirely

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes