Bird
0
0

What is the output of this Swift code?

medium📝 Predict Output Q13 of 15
Swift - Data Types
What is the output of this Swift code?
let a: Int = 7
let b: Double = 3.5
let c = Double(a) + b
print(c)
A10.5
B10
C7.0
DError: Cannot add Int and Double
Step-by-Step Solution
Solution:
  1. Step 1: Convert Int to Double explicitly

    a is Int 7, converted to Double 7.0 using Double(a).
  2. Step 2: Add converted Double and b

    Adding 7.0 + 3.5 results in 10.5.
  3. Final Answer:

    10.5 -> Option A
  4. Quick Check:

    7.0 + 3.5 = 10.5 [OK]
Quick Trick: Convert Int to Double before adding [OK]
Common Mistakes:
  • Forgetting to convert Int to Double
  • Expecting integer addition result
  • Assuming implicit conversion

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes