Advanced Kotlin
Q79 / 100

What is Kotlin's tail-recursive optimization (tailrec)?

Correct! Well done.

Incorrect.

The correct answer is B) The compiler replaces a tail-recursive function with a loop to prevent StackOverflowError

B

Correct Answer

The compiler replaces a tail-recursive function with a loop to prevent StackOverflowError

Explanation

tailrec fun factorial(n: Long, acc: Long = 1): Long is transformed by the compiler into a while loop, allowing deep recursion without stack overflow.

Progress
79/100