Bird
0
0

Identify the error in this Swift code:

medium📝 Debug Q14 of 15
Swift - Variables and Constants
Identify the error in this Swift code:
let a = 10 let b = 20
print(a + b)
AVariable names are invalid
BMissing semicolon between statements on the same line
CMissing parentheses in print statement
DNo error, code runs fine
Step-by-Step Solution
Solution:
  1. Step 1: Check statement separation

    Two statements are on the same line without a semicolon separating them, which is invalid in Swift.
  2. Step 2: Confirm print syntax and variable names

    Print statement and variable names are correct; only missing semicolon causes error.
  3. Final Answer:

    Missing semicolon between statements on the same line -> Option B
  4. Quick Check:

    Multiple statements same line need semicolon [OK]
Quick Trick: Add semicolon between statements on the same line [OK]
Common Mistakes:
  • Ignoring missing semicolon error
  • Assuming print needs no parentheses
  • Thinking variable names cause error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes