use the fmt package to print a value of type int in go

Here's how you can use the fmt package in Go to print an integer value:

main.go
package main

import "fmt"

func main() {
    num := 42
    fmt.Printf("The value of num is %d", num)
}
104 chars
9 lines

Here, we've declared a variable num with a value of 42. We then use fmt.Printf to print the value of num with the %d format specifier. The %d format specifier is used for printing integers.

When you run this program, it should output:

main.go
The value of num is 42
23 chars
2 lines

related categories

gistlibby LogSnag