Question:

What output will be produced by the code below?

import Foundation
let number = 16
print("\(number) squared is \(number * number), and its square root is \(sqrt(number))")

Answer: This code will not compile.

Explanation: The sqrt() function can be called using two different types of parameter, neither of which are integers. In this example, Swift's type inference will consider number to be an Integer, which cannot be used by sqrt()unless you typecast it.


Keywords:

© 2017 QuizBucket.org