Bird
0
0

Identify the error in the following Swift code:

medium📝 Debug Q14 of 15
Swift - Data Types
Identify the error in the following Swift code:
let x = true
let y = false
let result = x & y
AMissing semicolon at the end of the line
BUsing single & instead of && for logical AND
CVariables x and y must be integers
DUsing let instead of var for result
Step-by-Step Solution
Solution:
  1. Step 1: Check logical AND operator usage

    In Swift, logical AND uses &&, not a single &.
  2. Step 2: Identify the syntax error

    Using & causes a compile error because it's a bitwise operator, not logical.
  3. Final Answer:

    Using single & instead of && for logical AND -> Option B
  4. Quick Check:

    Logical AND requires &&, not & [OK]
Quick Trick: Use && for logical AND, & is bitwise [OK]
Common Mistakes:
  • Confusing bitwise & with logical &&
  • Thinking semicolons are required in Swift
  • Assuming let cannot be used for constants

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes