HexLibraryHexLibrary
</> HexCodeSign inSign up
PythonJavaScriptTypeScriptCC++JavaPHPGoRustRubyBashSQLLuaPerlCOBOLPascalDelphiFortranDartSwiftC#JuliaGroovyRElixirHaskellKotlinScalaClassic ASPClipperMS-DOS
LESSONS
Introduction to GoVariablesData TypesOperatorsStringsArray & SliceMap (Dictionary)Conditions (if / switch)Loops (for)Functions
REFERENCE
📖 Overview
🖥️ Output
📦 Variables
🔢 Numbers & Math
✍️ String
📋 Array & Slice
🗂️ Map
🔁 Condition & Loop
🧩 Function
funcMultiple returnVariadic (...)
Go›REFERENCE›Function
🧩

Function

Function definition, multiple returns, and variadic functions.

CommandDescription
funcDefines a function.
Multiple returnReturns multiple values.
Variadic (...)Takes a variable number of arguments.

func

Try it yourself →

Defines a function.

Syntax

func name(p type) returnType { }

Description

Parameter type comes AFTER the name. Return type is specified after the parentheses.

Example

package main
import "fmt"
func square(x int) int {
    return x * x
}
func main() {
    fmt.Println(square(5))
}

Expected output

25

When to use?

Preventing code repetition.

Multiple return

Try it yourself →

Returns multiple values.

Syntax

func name() (type1, type2) { return a, b }

Description

Go functions can return multiple values — especially the (result, error) pattern is common.

Example

package main
import "fmt"
func bolVeKalan(a, b int) (int, int) {
    return a / b, a % b
}
func main() {
    b, k := bolVeKalan(17, 5)
    fmt.Println(b, k)
}

Expected output

3 2

When to use?

Dual results like result + error, quotient + remainder.

Variadic (...)

Try it yourself →

Takes a variable number of arguments.

Syntax

func name(numbers ...int) { }

Description

...type gathers an arbitrary number of arguments into a slice.

Example

package main
import "fmt"
func addUp(numbers ...int) int {
    t := 0
    for _, s := range numbers {
        t += s
    }
    return t
}
func main() {
    fmt.Println(addUp(1, 2, 3, 4))
}

Expected output

10

When to use?

Indeterminate number of arguments (addUp, concatenate).

HexLibraryHexLibrary

Learn programming more clearly. Every command is explained line by line with colors, reinforced with runnable exercises, test your code instantly — all in one place, free.

Learn

  • Home
  • Languages & Lessons
  • HexCode

Company

  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

Other Projects

  • HexToolz
  • Free Service Manuals
© 2026 HexLibrary · The clearest way to learn code