Recall & Review
beginner
What is an Int in Swift?
An Int is a whole number without any decimal part. It can be positive, negative, or zero, like 5, -3, or 0.
Click to reveal answer
beginner
What is the difference between Double and Float in Swift?
Double stores decimal numbers with more precision (more digits after the decimal) than Float. Double uses 64 bits, Float uses 32 bits.
Click to reveal answer
intermediate
Why choose Double over Float?
Choose Double when you need more accurate decimal numbers, like in money calculations or measurements.
Click to reveal answer
beginner
How do you declare a variable of type Int in Swift?
Use
var number: Int = 10 to declare an integer variable named number with value 10.Click to reveal answer
beginner
What happens if you try to store a decimal number in an Int variable?
You get an error because Int cannot hold decimal numbers. You must use Double or Float for decimals.
Click to reveal answer
Which Swift type would you use to store the number 42?
✗ Incorrect
42 is a whole number, so Int is the best choice.
Which type has more precision for decimal numbers?
✗ Incorrect
Double uses 64 bits and stores more precise decimal numbers than Float.
What will happen if you assign 3.14 to an Int variable?
✗ Incorrect
Int cannot hold decimals, so Swift gives a compile-time error.
Which type uses 32 bits to store numbers?
✗ Incorrect
Float uses 32 bits, Double uses 64 bits.
Why might you prefer Double over Float?
✗ Incorrect
Double stores decimal numbers more precisely than Float.
Explain the differences between Int, Double, and Float in Swift.
Think about whole vs decimal numbers and precision.
You got /3 concepts.
When should you use Double instead of Float in your Swift programs?
Consider accuracy and size of numbers.
You got /3 concepts.