Bird
0
0

What is the output of this Kotlin code?

medium📝 Predict Output Q4 of 15
Kotlin - Operators and Expressions
What is the output of this Kotlin code?
val result = 8 / 2 * (2 + 2)
println(result)
A16
B1
C8
DError
Step-by-Step Solution
Solution:
  1. Step 1: Evaluate parentheses first

    (2 + 2) = 4.
  2. Step 2: Apply operator precedence left to right for division and multiplication

    8 / 2 = 4, then 4 * 4 = 16.
  3. Final Answer:

    16 -> Option A
  4. Quick Check:

    Parentheses first, then left-to-right * and / [OK]
Quick Trick: Parentheses first, then * and / left to right [OK]
Common Mistakes:
MISTAKES
  • Multiplying before dividing
  • Ignoring parentheses
  • Assuming error due to parentheses

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes