Standard library / flag
flag.IntVar()
Registers a flag on the default command line. Binds existing int storage rather than returning a pointer. 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 IntVar(p *int, name string, value int, usage string)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| p | *int | Pointer to storage updated during parsing. |
| name | string | Name of the flag or flag set. |
| value | int | Default value for registration, or text to parse for Set. |
| usage | string | Help text describing the flag. |
Working Example
Example Snippetgo
package main
import ( "flag" "fmt")
func main() { var v int; flag.IntVar(&v, "x", 3, "value"); flag.Parse(); fmt.Println(v) }