What is Functions?
A function is a unit of code that performs a special task. In programming, the function is used to break the code into smaller modules which makes the program more manageable.
We can call sum(x, y) at any number of times and it will return the sum of two numbers. So, the function avoids the repetition of code and makes the code more reusable.
Note: There is a space between closing bracket ‘)’ and opening ‘{‘ .
Kotlin functions
In Kotlin, functions are used to encapsulate a piece of behavior that can be executed multiple times. Functions can accept input parameters, return values, and provide a way to encapsulate complex logic into reusable blocks of code.
Learn Kotlin Functions
- What is Functions?
- Example of a Function
- Types of Functions in Kotlin
- 1. Kotlin User-Defined Function
- 2. Kotlin Standard Library Function
- Advantages and Disadvantages in Kotlin Function