Bird
0
0

What will be the output of this Kotlin code?

medium📝 Predict Output Q13 of 15
Kotlin - Variables and Type System
What will be the output of this Kotlin code?
var x = 5
x = 10
println(x)
A10
BCompilation error
C5
DRuntime error
Step-by-Step Solution
Solution:
  1. Step 1: Understand variable assignment

    Variable x is declared mutable with initial value 5, then changed to 10.
  2. Step 2: Print the current value of x

    The print statement outputs the updated value 10.
  3. Final Answer:

    10 -> Option A
  4. Quick Check:

    Mutable var allows reassignment, so output is 10 [OK]
Quick Trick: var lets you change value; print latest value [OK]
Common Mistakes:
MISTAKES
  • Thinking var variables cannot be reassigned
  • Expecting initial value to print
  • Confusing compilation and runtime errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes