Question:

What output will be produced by the code below?

func greet(_ name: inout String) {
    name = name.uppercased()
    print("Greetings, \(name)!")
}

var name = "Mal"
greet(name)
print("Goodbye, \(name)!")

Correct answer: This code will not compile.

Explanation: The greet() function declares its name parameter to be inout, which means it must be passed in using &. The code should be written greet(&name).

 


Keywords:

© 2017 QuizBucket.org