DEV Community

Ammar-Baig19
Ammar-Baig19

Posted on

Functions And Pointers In Go Lang:

Functions
A function is a separate, self-contained block of code that accomplishes a particular goal. Here are a few significant parts of functions in Go Lang:

Syntax of defining function: The syntax for defining a function in Go Lang is as follows:

*func functionName(parameter1 type, parameter2 type) returnType {
// function body
}
*

Parameters:
In Go Lang, functions can receive zero or more input parameters, which are the data that are passed to the function. The name of the function is followed by parentheses, which define the parameters. Every boundary has a name and a type.

Calling function:
A function can be called by its name followed by the arguments in parentheses. For example, functionName(argument1, argument2).
Function overloading: Go Lang does not support function overloading. Each function must have a unique name.

Return types:
Functions in Go Lang can return zero or one value, or multiple values. The return type is defined after the parameter list.

Top comments (0)