Bird
0
0

Which of the following is the correct way to declare a variadic parameter in Swift?

easy📝 Syntax Q12 of 15
Swift - Functions
Which of the following is the correct way to declare a variadic parameter in Swift?
Afunc sum(numbers: Int*) { }
Bfunc sum(numbers: [Int]) { }
Cfunc sum(numbers: Int...) { }
Dfunc sum(numbers: Int) { }
Step-by-Step Solution
Solution:
  1. Step 1: Recall variadic syntax in Swift

    Variadic parameters use three dots (...) after the type.
  2. Step 2: Check each option

    func sum(numbers: Int...) { } uses 'Int...' which is correct syntax for variadic parameters.
  3. Final Answer:

    func sum(numbers: Int...) { } -> Option C
  4. Quick Check:

    Variadic syntax = Type... [OK]
Quick Trick: Look for three dots (...) after type for variadic [OK]
Common Mistakes:
  • Using asterisk (*) instead of three dots
  • Using array type instead of variadic
  • Missing dots after type

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes