Welcome to the Kotlin Functions and Lambdas Quiz! This quiz will test your understanding of Kotlin’s functions and lambda expressions, essential tools for writing clean, efficient, and reusable code. You’ll explore key concepts such as function declarations, parameter handling, lambda expressions, higher-order functions, and more. Each question is crafted to reinforce your knowledge and provide valuable insights into best practices when working with functions and lambdas in Kotlin.
1.
Which of the following is an example of a single-expression function?
2.
How can you execute a lambda directly without assigning it to a variable?
3.
What will be the output of the following code?
val multiply = { x: Int, y: Int -> x * y };
println(multiply(3, 4))
4.
Which Kotlin code correctly shows a lambda being assigned to a variable?
5.
What does the vararg keyword allow you to do in Kotlin?
6.
How would you declare a function that returns a lambda?
7.
Which function type represents a function that accepts an Int and returns a String?
8.
Which keyword is used to specify that a Kotlin function parameter is optional?
9.
How are functions declared to accept a lambda as a parameter?
10.
What happens when you place parentheses after a lambda expression?
11.
Which statement about Kotlin lambda expressions is correct?
12.
Which code snippet correctly demonstrates passing a function reference as an argument?
13.
What is the main advantage of using higher-order functions in Kotlin?
14.
How do you declare a function that returns a function as its result?
15.
What is a function in Kotlin?
16.
Which syntax assigns a function reference to a variable in Kotlin?
17.
How can a lambda be directly executed in Kotlin?
18.
What is a lambda expression in Kotlin?
19.
Which of the following is the correct syntax for a function with a variable number of string parameters?
20.
What keyword is used to specify that a function can accept a variable number of parameters?
21.
What is the purpose of default parameters in Kotlin functions?
22.
How do you handle return values from a Kotlin function?
23.
What is a local function in Kotlin?
24.
Which of the following is a correct single-expression function that multiplies two numbers?
25.
What is a single expression function in Kotlin?
26.
What is the syntax for calling a function named sayHello that takes no parameters and returns no value?
27.
Which keyword is used to declare a function in Kotlin?
28.
What is the difference between parameters and arguments in the context of functions?