Bird
0
0

What is the output of the following Swift code?

medium📝 Predict Output Q4 of 15
Swift - Data Types
What is the output of the following Swift code?
let x = false
let y = true
print(x || !y && y)
Afalse
Btrue
CCompilation error
Dnil
Step-by-Step Solution
Solution:
  1. Step 1: Evaluate the NOT operator

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

    !y && y becomes false && true which is false.
  3. Step 3: Evaluate the OR operator

    x || (result) becomes false || false which is false.
  4. Final Answer:

    false -> Option A
  5. Quick Check:

    Operator precedence and NOT evaluation = false [OK]
Quick Trick: Remember ! has highest precedence, then &&, then || [OK]
Common Mistakes:
  • Evaluating || before &&
  • Misinterpreting !true
  • Assuming syntax error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes