Syntax

Go Define a Function Syntax

In Go, define a function: defines a function with multiple returns — func div(a, b int) (int, error) { ... }

Quick Answer

Syntax
func div(a, b int) (int, error) { ... }
GoSyntax

Define a Function

Code example
func div(a, b int) (int, error) { ... }

Defines a function with multiple returns.

Learn More

How to define a function in Go

  1. Open your Go file or editor.
  2. Copy the example, then replace its sample names and values for your code.

Go Define a Function Syntax

Use func div(a, b int) (int, error) { ... }.

Related Syntax References

Frequently asked questions

What is the Go syntax for define a function?

Use this pattern: func div(a, b int) (int, error) { ... }

Can I copy this Go code example?

Yes. Use Copy code and adapt the example to your program.

Is this Go syntax different on Mac or Windows?

No. The language syntax is the same across operating systems.

Official source · How we verify