Bird
0
0

What will be the output of this Swift code?

medium📝 Predict Output Q13 of 15
Swift - Operators and Expressions
What will be the output of this Swift code?
let a = true
let b = false
print(a || b && !b)
ASyntax Error
Btrue
Cfalse
Dnil
Step-by-Step Solution
Solution:
  1. Step 1: Evaluate the NOT operator

    !b means !false which is true.
  2. Step 2: Evaluate AND operator

    b && !b is false && true which is false.
  3. Step 3: Evaluate OR operator

    a || (result of AND) is true || false which is true.
  4. Final Answer:

    true -> Option B
  5. Quick Check:

    OR with true = true [OK]
Quick Trick: Remember NOT first, then AND, then OR [OK]
Common Mistakes:
  • Ignoring operator precedence
  • Evaluating OR before AND
  • Misunderstanding ! operator

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes