Bird
0
0

Find the error in this Kotlin code snippet:

medium📝 Debug Q6 of 15
Kotlin - Operators and Expressions
Find the error in this Kotlin code snippet:
val x = true
val y = false
val result = x & y || !x
println(result)
AUsing single & instead of && for logical AND
BMissing parentheses around & and ||
CNo error, code runs fine
DIncorrect negation operator
Step-by-Step Solution
Solution:
  1. Step 1: Identify the operators

    & is valid non-short-circuit logical AND for Boolean, || is logical OR, ! is NOT. No syntax issues.
  2. Step 2: Verify execution

    true & false = false, !true = false, false || false = false. println(false) works fine.
  3. Final Answer:

    No error, code runs fine -> Option C
  4. Quick Check:

    Code compiles and runs correctly [OK]
Quick Trick: Remember & is also logical AND (non-short-circuit) [OK]
Common Mistakes:
MISTAKES
  • Thinking & is invalid for Boolean
  • Confusing & with bitwise only
  • Expecting syntax error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes