Bird
0
0

What will be printed by this Swift code?

medium📝 Predict Output Q5 of 15
Swift - Data Types
What will be printed by this Swift code?
let a = true
let b = false
let c = true
print(a && b || c)
ARuntime error
Bfalse
Cnil
Dtrue
Step-by-Step Solution
Solution:
  1. Step 1: Evaluate the AND operation first

    a && b is true && false which is false.
  2. Step 2: Evaluate the OR operation

    false || c is false || true which is true.
  3. Final Answer:

    true -> Option D
  4. Quick Check:

    Logical AND before OR = true [OK]
Quick Trick: && evaluated before || in Swift expressions [OK]
Common Mistakes:
  • Evaluating || before &&
  • Confusing true and false
  • Expecting runtime error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes