Question:

What output will be produced by the code below?

func greet(names: String...) {
    print("Criminal masterminds:", names.joined(separator: ", "))
}

greet(names: "Malcolm", "Kaylee", "Zoe")

Correct answer: "Criminal masterminds: Malcolm, Kaylee, Zoe".

Explanation: The greet() method is declared as accepting a variadic string parameter, which means it should be called using one or more strings that will be made accessible as an array inside the function. The greet() method takes that array, joins it using commas, then prints it out as part of a larger message.


Keywords:

© 2017 QuizBucket.org