Bird
0
0

What will be the output of the following Swift code?

medium📝 Predict Output Q13 of 15
Swift - Functions
What will be the output of the following Swift code?
func greet(person name: String) {
    print("Hello, \(name)!")
}
greet(person: "Anna")
AHello, Anna!
BError: Missing argument label
CHello, name!
DHello, person!
Step-by-Step Solution
Solution:
  1. Step 1: Understand argument label and parameter name

    The function uses argument label person and parameter name name. The call uses person: "Anna".
  2. Step 2: Check the print statement

    Inside the function, name is used, so it prints "Hello, Anna!".
  3. Final Answer:

    Hello, Anna! -> Option A
  4. Quick Check:

    Argument label person calls parameter name name [OK]
Quick Trick: Argument label used in call, parameter name used inside function [OK]
Common Mistakes:
  • Confusing argument label with parameter name in print
  • Calling function without argument label
  • Expecting argument label to print

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes