BeginnerFunctions

Function with Return Value

Return a value from a function.

kotlin
fun add(a: Int, b: Int): Int {
    return a + b
}

fun main() {
    val result = add(10, 20)
    println(result)
}
Output
30

Explanation

The function declares return type Int after the parameters. return sends the value back to the caller.

Related Tutorials