Bird
0
0

Consider this function:

medium📝 Predict Output Q5 of 15
Swift - Functions
Consider this function:
func describe(age: Int, of person: String) {
    print("\(person) is \(age) years old.")
}

describe(age: 25, of: "Sam")

What will be printed?
A25 is Sam years old.
BSam of 25 years old.
CError: Missing argument label
DSam is 25 years old.
Step-by-Step Solution
Solution:
  1. Step 1: Identify argument labels and parameter names

    The function has argument labels age and of. The call uses both labels correctly.
  2. Step 2: Understand the print statement output

    The print statement uses parameter names person and age to format the string. So it prints "Sam is 25 years old.".
  3. Final Answer:

    Sam is 25 years old. -> Option D
  4. Quick Check:

    Correct labels and parameters print expected string [OK]
Quick Trick: Match argument labels in call exactly as declared [OK]
Common Mistakes:
  • Swapping argument labels in call
  • Using parameter names instead of argument labels in call
  • Misreading print statement placeholders

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes