Swift - FunctionsWhich 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...) {}Check Answer
Step-by-Step SolutionSolution:Step 1: Recall Swift variadic syntaxVariadic parameters use three dots (...) after the type.Step 2: Check each optionOnly func sum(numbers: Int...) {} uses 'Int...' which is correct syntax.Final Answer:func sum(numbers: Int...) {} -> Option DQuick Check:Variadic syntax = type followed by ... [OK]Quick Trick: Use three dots (...) after type for variadic [OK]Common Mistakes:Using array syntax instead of variadicUsing * or [] which are invalid in SwiftOmitting the dots after type
Master "Functions" in Swift9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More Swift Quizzes Collections - Set algebra (union, intersection, difference) - Quiz 1easy Collections - Set creation and operations - Quiz 6medium Control Flow - Switch must be exhaustive - Quiz 10hard Control Flow - If and if-else statements - Quiz 1easy Control Flow - Switch must be exhaustive - Quiz 11easy Data Types - Tuples for grouped values - Quiz 15hard Loops - While loop - Quiz 11easy Loops - For-in loop with collections - Quiz 8hard Operators and Expressions - Ternary conditional operator - Quiz 2easy Variables and Constants - Var for variables (mutable) - Quiz 1easy