Bird
0
0

Which of the following is the correct way to declare a variable price as a Double with value 19.99 in Swift?

easy📝 Syntax Q12 of 15
Swift - Data Types

Which of the following is the correct way to declare a variable price as a Double with value 19.99 in Swift?

?
Avar price: Int = 19.99
Bvar price = 19.99f
Cvar price: Double = 19.99
Dvar price: Float = "19.99"
Step-by-Step Solution
Solution:
  1. Step 1: Check type and value compatibility

    Double can store decimal numbers like 19.99 correctly.
  2. Step 2: Validate syntax

    var price: Double = 19.99 uses correct syntax: variable name, type annotation, and decimal value.
  3. Final Answer:

    var price: Double = 19.99 -> Option C
  4. Quick Check:

    Double declaration syntax = var name: Double = value [OK]
Quick Trick: Use var name: Double = value for decimals [OK]
Common Mistakes:
  • Using 'f' suffix which is invalid in Swift
  • Assigning decimal to Int type
  • Using quotes for numbers

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes