Test: Swift - Forced Unwrapping of Optionals
5. var totalScore = 100 - what’s the type of totalScore variable in Swift?
Congratulations! Correct Answer.
You Answered: None. If you took the test, your answer will show up here.
Correct Answer: Int
ExplanationSwift infers the type of the variable by looking at the assigned value during initialization. Here 100 is an integer literal. And hence the type would be Int. I will not be an optional Int (i.e. not Int?) and assigning a nil value to totalScore after the above declaration will be an error.
Take the TestTake the complete test on this topic. You will be able to review answers to questions and get a test score.
Take the Test
Question 5 of 5