Bird
0
0

Which of the following is the correct syntax to declare a function with a vararg parameter in Kotlin?

easy📝 Syntax Q12 of 15
Kotlin - Functions

Which of the following is the correct syntax to declare a function with a vararg parameter in Kotlin?

fun printAll(____ numbers: Int) { for (n in numbers) println(n) }
Avar
Bvarargs
Cvararg
Dargs
Step-by-Step Solution
Solution:
  1. Step 1: Recall the exact keyword for variable arguments

    Kotlin uses vararg (singular) to declare variable number of arguments.
  2. Step 2: Check each option

    Only vararg matches the correct keyword; others are incorrect or invalid syntax.
  3. Final Answer:

    vararg -> Option C
  4. Quick Check:

    Keyword is vararg, not varargs [OK]
Quick Trick: Remember: vararg is singular keyword [OK]
Common Mistakes:
MISTAKES
  • Using 'varargs' instead of 'vararg'
  • Omitting the keyword entirely
  • Using 'var' or 'args' which are invalid here

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes