To create a function with multiple parameters in Go, you need to declare the function with the parameter names and types within the parentheses following the function name.
Here's an example of a function with three parameters:
main.go84 chars4 lines
In this example, the function is named addNumbers
and takes three parameters of type int
. The function returns the sum of the three input numbers.
Alternatively, you can also declare multiple parameters of the same type using the following syntax:
main.go81 chars4 lines
In this example, the multiplyNumbers
function also takes three parameters but all of them are of type int
. The function returns the product of the three input numbers.
Both functions can be called like this:
main.go66 chars3 lines
gistlibby LogSnag