Bird
0
0

What will be the output of this Swift code?

medium📝 Predict Output Q4 of 15
Swift - Operators and Expressions
What will be the output of this Swift code?
let x = true
let y = false
print(x && !y)
Atrue
Bfalse
Cnil
DCompilation error
Step-by-Step Solution
Solution:
  1. Step 1: Evaluate !y

    y is false, so !y is true.
  2. Step 2: Evaluate x && !y

    x is true, and !y is true, so true && true is true.
  3. Final Answer:

    true -> Option A
  4. Quick Check:

    True AND NOT false = true [OK]
Quick Trick: NOT false becomes true, AND with true stays true [OK]
Common Mistakes:
  • Confusing !y as false
  • Mixing AND with OR
  • Expecting runtime error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes