Which of the following is the correct way to write the number ten million (10,000,000) in Swift using underscores for readability?
hard📝 Application Q8 of 15
Swift - Data Types
Which of the following is the correct way to write the number ten million (10,000,000) in Swift using underscores for readability?
Alet number = 100_00000
Blet number = 1_0000_000
Clet number = 10000_000
Dlet number = 10_000_000
Step-by-Step Solution
Solution:
Step 1: Understand underscore usage
Swift allows underscores anywhere between digits to improve readability, but they must separate groups of digits logically.
Step 2: Analyze each option
let number = 10_000_000 correctly groups digits as 10_000_000, which is standard for ten million. Options B, C, and D have irregular groupings that do not represent the number correctly.
Final Answer:
let number = 10_000_000 -> Option D
Quick Check:
Underscores separate digit groups logically [OK]
Quick Trick:Use underscores to separate digits in groups of three [OK]
Common Mistakes:
Placing underscores in inconsistent or invalid positions
Grouping digits incorrectly leading to wrong values
Assuming underscores affect the numeric value
Master "Data Types" in Swift
9 interactive learning modes - each teaches the same concept differently