Bird
0
0

Identify the error in this Swift code snippet:

medium📝 Debug Q14 of 15
Swift - Data Types
Identify the error in this Swift code snippet:
var score: Int = "100"
print(score)
AVariable score is not initialized
BMissing semicolon at end of line
Cprint function syntax is incorrect
DType mismatch: assigning String to Int variable
Step-by-Step Solution
Solution:
  1. Step 1: Check variable type and assigned value

    score is declared as Int but assigned a String "100" which is invalid.
  2. Step 2: Understand Swift's strong typing rules

    Swift does not allow assigning a String to an Int variable without conversion.
  3. Final Answer:

    Type mismatch: assigning String to Int variable -> Option D
  4. Quick Check:

    Type mismatch error = Type mismatch: assigning String to Int variable [OK]
Quick Trick: Match variable type and assigned value exactly [OK]
Common Mistakes:
  • Thinking semicolon is required
  • Assuming implicit conversion from String to Int
  • Believing print syntax is wrong

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes