Which of the following is the correct way to write a floating-point literal with an exponent in Swift?
easy📝 Syntax Q3 of 15
Swift - Data Types
Which of the following is the correct way to write a floating-point literal with an exponent in Swift?
Alet value = 3.14e-2
Blet value = 3.14E+2
CAll of the above
Dlet value = 3.14e2
Step-by-Step Solution
Solution:
Step 1: Understand floating-point literals with exponents
Swift allows floating-point literals with 'e' or 'E' followed by an optional sign and digits.
Step 2: Check each option
let value = 3.14e2 uses lowercase 'e' with positive exponent. let value = 3.14E+2 uses uppercase 'E' with explicit plus sign. let value = 3.14e-2 uses lowercase 'e' with negative exponent. All are valid.
Final Answer:
All of the above -> Option C
Quick Check:
Floating-point exponent literals = all valid [OK]
Quick Trick:Use e or E with optional + or - for exponents [OK]
Common Mistakes:
Omitting the exponent digits after e/E
Using invalid characters in exponent
Confusing e with multiplication
Master "Data Types" in Swift
9 interactive learning modes - each teaches the same concept differently