Bird
0
0

Which of the following is the correct syntax to declare a variadic parameter named 'numbers' of type Int in Swift?

easy📝 Syntax Q3 of 15
Swift - Functions
Which of the following is the correct syntax to declare a variadic parameter named 'numbers' of type Int 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 Swift variadic syntax

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

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

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

    Variadic syntax = type followed by ... [OK]
Quick Trick: Use three dots (...) after type for variadic [OK]
Common Mistakes:
  • Using array syntax instead of variadic
  • Using * or [] which are invalid in Swift
  • Omitting the dots after type

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes