Bird
0
0

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:
  1. Step 1: Understand floating-point literals with exponents

    Swift allows floating-point literals with 'e' or 'E' followed by an optional sign and digits.
  2. 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.
  3. Final Answer:

    All of the above -> Option C
  4. 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

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes