Functions are generally the block of codes or statements in a program that gives the user the ability to reuse the same code which ultimately saves the excessive use of memory, acts as a time saver and more importantly, provides better readability of the code. So basically, a function is a collection of statements that perform some specific task and return the result to the caller. A function can also perform some specific task without returning anything.
The declaration of the function contains:
- func: It is a keyword in Go language, which is used to create a function.
- function_name: It is the name of the function.
- Parameter-list: It contains the name and the type of the function parameters.
- Return_type: It is optional and it contain the types of the values that function returns. If you are using return_type in your function, then it is necessary to use a return statement in your function.
Functions In Go Programming Language : https://www.geeksforgeeks.org/functions-in-go-language/