{infiniteZest} // Articles. Tutorials. Utilities.
Categories
Test: Swift - Integer Types

5. var score: Int = Int8.max - What’s the value of score in Swift?

 255 127 0 [CORRECT ANSWER] Error

Results
You Answered: None. If you took the test, your answer will show up here.
Explanation
Int8.max is 127 (the range is -128 to 127). However, here score is explicitly declared as Int. And Int8.max returns a value of type Int8. So, we are trying to assign a value of type Int8 to a variable of type Int. In Swift, automatic type conversion is not done. These value would have to be explicitly converted. Otherwise, it will result in an error.
Take the Test
Take 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

 Tags: This article goes through the usage of various integer types in Swift (including Int and UInt). Tags: Test on Integer types in Swift.

More Articles With Similar Tags
 Tags: Test on Integer types in Swift. Tags: This series of articles goes through the basics of Swift. It introduces Playgrounds and REPL; Variables and Constants; Int, Float, Bool; Tuples, Type Aliases, Type Inference, Type Safety, and more. Tags: This article discusses the boolean types in Swift and contrasts with how these types are used in C and Objective-C. Tags: Test on Boolean Types in Swift. Tags: This article talks about decimal numbers in Swift, including Float, Double, and CGFloat. Also talks about Binary, Octal, and Hexadecimal representations.