Function declaration syntax: things in parenthesis before function name in Go

In Go, the syntax for declaring a function is func functionname(parametername type) returntype { }. The function declaration starts with a func keyword followed by the functionname, and the parameters are specified between ( ) followed by the returntype of the function.

In the parenthesis before the function name, you can declare zero or more parameters the function will accept. Each parameter consists of a parameter name followed by its type.

After the parameter list, you can specify the function’s return type. This can be any valid Go type or void if the function does not return a value.


func add(x int, y int) int {
   return x + y

In this example, the add() function takes two integer parameters, x, and y. As a result, the function returns an integer value that represents the sum of x and y.

The parenthesis before the function name is the Go way of defining the object on which these functions will operate.

That’s it.

Leave a Comment