Bird
0
0

What will be the result of the expression true && false || true in Swift?

easy📝 Conceptual Q2 of 15
Swift - Data Types
What will be the result of the expression true && false || true in Swift?
Afalse
Bnil
Ctrue
DSyntax error
Step-by-Step Solution
Solution:
  1. Step 1: Understand operator precedence in Swift

    Logical AND (&&) has higher precedence than logical OR (||), so evaluate true && false first, which is false.
  2. Step 2: Evaluate the full expression

    Now the expression becomes false || true, which evaluates to true.
  3. Final Answer:

    true -> Option C
  4. Quick Check:

    Operator precedence: && before || = true [OK]
Quick Trick: && is evaluated before || in Swift expressions [OK]
Common Mistakes:
  • Evaluating || before &&
  • Assuming syntax error
  • Confusing true/false values

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes