Bird
0
0

Which of the following function declarations correctly uses an argument label to and a parameter name recipient?

easy📝 Conceptual Q2 of 15
Swift - Functions
Which of the following function declarations correctly uses an argument label to and a parameter name recipient?
Afunc sendMessage(recipient to: String) { print("Sending to \(to)") }
Bfunc sendMessage(to recipient: String) { print("Sending to \(recipient)") }
Cfunc sendMessage(to: recipient String) { print("Sending to \(recipient)") }
Dfunc sendMessage(to recipient String) { print("Sending to \(recipient)") }
Step-by-Step Solution
Solution:
  1. Step 1: Recall Swift syntax for argument labels and parameter names

    The correct syntax is: argumentLabel parameterName: Type. For example, to recipient: String.
  2. Step 2: Check each option for correct syntax

    func sendMessage(to recipient: String) { print("Sending to \(recipient)") } matches the syntax. Options A, C, and D have incorrect order or missing punctuation.
  3. Final Answer:

    func sendMessage(to recipient: String) { print("Sending to \(recipient)") } -> Option B
  4. Quick Check:

    Correct argument label syntax = func sendMessage(to recipient: String) { print("Sending to \(recipient)") } [OK]
Quick Trick: Argument label comes before parameter name with colon [OK]
Common Mistakes:
  • Swapping argument label and parameter name order
  • Missing colon between parameter name and type
  • Using invalid syntax like multiple colons

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes