Bird
0
0

Identify the error in this Swift code:

medium📝 Debug Q6 of 15
iOS Swift - Swift Language Essentials
Identify the error in this Swift code:
var name: String
print(name)
AMissing semicolon after variable declaration
BVariable 'name' is used before being initialized
CString type cannot be used without optional
Dprint statement syntax is incorrect
Step-by-Step Solution
Solution:
  1. Step 1: Check variable initialization

    Variable 'name' is declared but not assigned a value before use.
  2. Step 2: Understand Swift's requirement

    Swift requires variables to be initialized before use to avoid runtime errors.
  3. Final Answer:

    Variable 'name' is used before being initialized -> Option B
  4. Quick Check:

    Uninitialized variable usage causes error [OK]
Quick Trick: Always initialize variables before use [OK]
Common Mistakes:
  • Thinking semicolons are required
  • Assuming String must be optional
  • Believing print syntax is wrong

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes