Bird
0
0

What is the output of the following Swift code?

medium📝 Predict Output Q13 of 15
Swift - Data Types
What is the output of the following Swift code?
let a = true
let b = false
print(a || b && !a)
ASyntax error
Bfalse
Ctrue
Dnil
Step-by-Step Solution
Solution:
  1. Step 1: Evaluate the NOT operator

    !a means NOT true, which is false.
  2. Step 2: Evaluate AND operation

    b && !a is false && false, which is false.
  3. Step 3: Evaluate OR operation

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

    true -> Option C
  5. Quick Check:

    Logical operators follow precedence: NOT, AND, OR [OK]
Quick Trick: Remember operator precedence: ! before && before || [OK]
Common Mistakes:
  • Ignoring operator precedence
  • Evaluating OR before AND
  • Confusing !a as true

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes