Bird
0
0

Find the error in this Swift snippet:

medium📝 Debug Q7 of 15
Swift - Data Types
Find the error in this Swift snippet:
let name: String = 12345
ANo error, implicit conversion happens
BCompile-time error: cannot assign Int to String
CRuntime error when printing name
DSyntax error due to missing quotes
Step-by-Step Solution
Solution:
  1. Step 1: Check type and assigned value

    name is declared as String but assigned an Int value 12345.
  2. Step 2: Understand Swift's type rules

    Swift does not convert Int to String automatically, causing compile-time error.
  3. Final Answer:

    Compile-time error: cannot assign Int to String -> Option B
  4. Quick Check:

    Strong typing disallows mismatched assignments [OK]
Quick Trick: String variables need string values in quotes [OK]
Common Mistakes:
  • Assuming implicit conversion from Int to String
  • Thinking error is runtime, not compile-time
  • Ignoring quotes for string literals

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes