Built-in function

Go max()

Returns the greatest of one or more ordered arguments. Compatible ordered types are required; it is not a variadic function accepting a slice expansion. Strings compare by bytes; floating-point NaN propagates and positive zero wins over negative zero. Example prints 11. Requires Go 1.21.

Formal Syntax & Structure

go syntaxgo
max(x, y, ...)

Parameters & Attributes

NameTypeDescription
xordered valueFirst candidate.
otherscompatible ordered valuesAdditional candidates.

Return Value

common argument type or untyped constant

Greatest argument value.

Working Example

Example Snippetgo
package main
import "fmt"
func main() {  fmt.Println(max(4, 11, 7))}
Go Reference