Bird
0
0

You want to declare a variable that can hold a decimal number and change later. Which declaration is correct?

hard📝 Application Q8 of 15
iOS Swift - Swift Language Essentials
You want to declare a variable that can hold a decimal number and change later. Which declaration is correct?
Alet price = 9.99
Bvar price: Double = 9.99
Cvar price: Int = 9.99
Dlet price: Float = 9
Step-by-Step Solution
Solution:
  1. Step 1: Identify variable mutability

    Variable must be changeable, so use var.
  2. Step 2: Choose correct type for decimal

    Decimal numbers require Double or Float, but Double is preferred for precision.
  3. Step 3: Check value and type match

    Value 9.99 matches Double type.
  4. Final Answer:

    var price: Double = 9.99 -> Option B
  5. Quick Check:

    Mutable decimal variable = D [OK]
Quick Trick: Use var with Double for changeable decimals [OK]
Common Mistakes:
  • Using let for changeable values
  • Assigning decimal to Int type
  • Using Float without reason

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes