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
| Name | Type | Description |
|---|---|---|
| x | ordered value | First candidate. |
| others | compatible ordered values | Additional 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))}