Bird
0
0

What will be the output of this Swift code?

medium📝 Predict Output Q13 of 15
Swift - Data Types
What will be the output of this Swift code?
let number: Int = 10
let text: String = "10"
print(number == Int(text)!)
Afalse
BCompilation error
Ctrue
DRuntime error
Step-by-Step Solution
Solution:
  1. Step 1: Understand type conversion

    text is a String "10". Int(text)! converts it to Int 10 safely.
  2. Step 2: Compare values

    number is Int 10, Int(text)! is also 10, so number == Int(text)! is true.
  3. Final Answer:

    true -> Option C
  4. Quick Check:

    10 == 10 is true [OK]
Quick Trick: Convert string to Int before comparing [OK]
Common Mistakes:
  • Assuming string and int compare directly
  • Ignoring forced unwrap with !
  • Expecting false because types differ

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes