Bird
0
0

Why does Swift require explicit type conversion when adding an Int and a Double?

hard📝 Conceptual Q10 of 15
iOS Swift - Swift Language Essentials
Why does Swift require explicit type conversion when adding an Int and a Double?
ABecause Double cannot store numbers
BBecause Swift does not support addition
CBecause Int is a string type
DBecause Int and Double are different types and cannot be added directly
Step-by-Step Solution
Solution:
  1. Step 1: Understand type safety in Swift

    Swift is strict about types; Int and Double are distinct types.
  2. Step 2: Explain why conversion is needed

    They cannot be added directly without converting one type to match the other.
  3. Final Answer:

    Because Int and Double are different types and cannot be added directly -> Option D
  4. Quick Check:

    Type safety requires explicit conversion [OK]
Quick Trick: Swift requires matching types for arithmetic operations [OK]
Common Mistakes:
  • Thinking Int is string
  • Believing Swift disallows addition
  • Ignoring type differences

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes