Bird
0
0

What will this Kotlin code print?

medium📝 Predict Output Q5 of 15
Kotlin - Data Types
What will this Kotlin code print?
val x = 0b1010_1010
val y = 0x4B
println(x - y)
A101
B85
C95
DSyntax error
Step-by-Step Solution
Solution:
  1. Step 1: Convert binary and hex literals to decimal

    0b1010_1010 is binary for 170 decimal. 0x4B is hex for 75 decimal.
  2. Step 2: Calculate the subtraction

    170 - 75 = 95.
  3. Final Answer:

    95 -> Option C
  4. Quick Check:

    Binary - Hex decimal = 95 [OK]
Quick Trick: Convert both to decimal before subtracting [OK]
Common Mistakes:
MISTAKES
  • Confusing hex 0x4B as decimal 4B
  • Misreading binary digits
  • Assuming syntax error due to underscores

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes