Variadic Parameter vs. Array | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Variadic Parameter vs. Array

What is the purpose of a variadic parameter when we can just use an array instead?

3rd May 2017, 11:55 PM
FishermanMan
3 Answers
+ 11
I think using the variadic parameter is easier than using an array. If you are going to use an array you have to create the array and then pass it to the function. But with the variadic parameter, you just pass the arguments to the function and the array is created for you. Edited: Although variadic parameters are considered sintatic sugar, it does have some limitations: - You can have only one in a function. - It must come last. In situations where you do want to overcome such limitations use arrays.
4th May 2017, 12:14 AM
Ulisses Cruz
Ulisses Cruz - avatar
4th May 2017, 12:45 AM
Ulisses Cruz
Ulisses Cruz - avatar
0
Thanks!
4th May 2017, 12:32 AM
FishermanMan