Standard library / flag

flag.Int()

Registers a flag on the default command line. Signed machine-width integer; accepts decimal, hexadecimal and other supported integer literal forms. Run with arguments: ["-x=7"]. Expected stdout: '7\n'.

Formal Syntax & Structure

go syntaxgo
func Int(name string, value int, usage string) *int

Parameters & Attributes

NameTypeDescription
namestringName of the flag or flag set.
valueintDefault value for registration, or text to parse for Set.
usagestringHelp text describing the flag.

Return Value

*int

Registers a flag on the default command line.

Working Example

Example Snippetgo
package main
import (  "flag"  "fmt")
func main() { v := flag.Int("x", 3, "value"); flag.Parse(); fmt.Println(*v) }
Go Reference