Bird
0
0

What will be the output of this Kotlin code?

medium📝 Predict Output Q13 of 15
Kotlin - Functions
What will be the output of this Kotlin code?
fun square(x: Int) = x * x
println(square(4))
A16
B4
Cx * x
DCompilation error
Step-by-Step Solution
Solution:
  1. Step 1: Understand the function behavior

    The function square returns the product of x times x.
  2. Step 2: Calculate the output for input 4

    4 * 4 = 16, so square(4) returns 16, which is printed.
  3. Final Answer:

    16 -> Option A
  4. Quick Check:

    4 squared = 16 [OK]
Quick Trick: Multiply input by itself for square function [OK]
Common Mistakes:
MISTAKES
  • Expecting the expression as a string output
  • Confusing input with output
  • Thinking it causes a compile error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes