Bird
0
0

What is the output of the following Kotlin code?

medium📝 Predict Output Q13 of 15
Kotlin - Data Types
What is the output of the following Kotlin code?
val a = true
val b = false
println(a || b && !b)
Afalse
Bnull
Ctrue
DCompilation error
Step-by-Step Solution
Solution:
  1. Step 1: Evaluate NOT operator

    !b means !false, which is true.
  2. Step 2: Evaluate AND operator

    b && !b means false && true, which is false.
  3. Step 3: Evaluate OR operator

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

    true -> Option C
  5. Quick Check:

    Logical operators follow precedence: !, &&, then || [OK]
Quick Trick: Remember operator precedence: ! > && > || [OK]
Common Mistakes:
MISTAKES
  • Ignoring operator precedence
  • Evaluating OR before AND
  • Confusing !b value

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes