Function is a group of statements that perform some task. Functions are used in programming to break code in small modules to reuse the code. Function is declared using fun keyword in kotlin language.
In this article, You will learn how to create and call functions in kotlin programming language.
There are basic two types of functions in Kotlin:
- Standard Library Functions
- User Defined Functions
Standard Library Kotlin Functions
Standard library functions are native functions in kotlin language which are always available for use. This functions can be called by using arguments in kotlin language.
User Defined Functions
User defined functions are created by user. First we need to define this type of functions before call them, I already mentioned that functions are declared by fun keyword in kotlin. Then We need to give name of the function to identify it from various functions.
Parameters are defined using pascal notation like name of parameter: its type in kotlin. Parameters which are defined in function are called formal parameters. Parameters which are used at call of function are called actual parameters. Parameters in function are separated by comma.
Here name, age, club_name are formal parameters and playerName, playerAge, playerClub are actual parameters.
Function with return value