Bird
0
0

What will be the output of the following Kotlin code?

medium📝 Predict Output Q4 of 15
Kotlin - Functions
What will be the output of the following Kotlin code?
fun square(num: Int): Int {
    return num * num
}

fun main() {
    println(square(5))
}
A5
B10
C25
DCompilation error
Step-by-Step Solution
Solution:
  1. Step 1: Understand the function

    The function square takes an integer num and returns num * num.
  2. Step 2: Evaluate the call

    Calling square(5) computes 5 * 5 = 25.
  3. Final Answer:

    25 -> Option C
  4. Quick Check:

    Output matches expected square value [OK]
Quick Trick: Multiply parameter by itself for square [OK]
Common Mistakes:
MISTAKES
  • Confusing multiplication with addition
  • Expecting function to print instead of return
  • Syntax errors in function declaration

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes