Bird
0
0

What will be the output of the following Swift code?

medium📝 Predict Output Q4 of 15
Swift - Operators and Expressions
What will be the output of the following Swift code?
let a = 5
let b = 10
print(a != b)
A10
Btrue
C5
Dfalse
Step-by-Step Solution
Solution:
  1. Step 1: Understand the != operator

    The operator != checks if two values are not equal. Here, a is 5 and b is 10.
  2. Step 2: Evaluate the expression a != b

    Since 5 is not equal to 10, the expression returns true.
  3. Final Answer:

    true -> Option B
  4. Quick Check:

    5 != 10 is true [OK]
Quick Trick: != returns true if values differ [OK]
Common Mistakes:
  • Thinking != returns false if values differ
  • Confusing output with variable values
  • Expecting numeric output instead of boolean

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes