Bird
0
0

Find the error in this Swift code snippet:

medium📝 Debug Q7 of 15
Swift - Data Types
Find the error in this Swift code snippet:
let number = 0o89
AOctal literals must start with 0x
BOctal literals cannot contain digits 8 or 9
CMissing decimal point for floating number
DUnderscores required for readability
Step-by-Step Solution
Solution:
  1. Step 1: Recall octal literal rules

    Octal literals start with 0o and only digits 0-7 are allowed.
  2. Step 2: Identify invalid digits

    The literal 0o89 contains digits 8 and 9 which are invalid in octal.
  3. Final Answer:

    Octal literals cannot contain digits 8 or 9 -> Option B
  4. Quick Check:

    Octal digits allowed = 0 to 7 only [OK]
Quick Trick: Octal digits must be 0-7 after 0o prefix [OK]
Common Mistakes:
  • Using digits 8 or 9 in octal literals
  • Confusing octal prefix 0o with hex 0x
  • Expecting decimal behavior from octal literals

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes