skip to content
Alvin Lucillo

Printing the memory address of variable

/ 1 min read

You can use %p directive to get the memory address of a variable.

package main

import "fmt"

func main() {
	item := "hello"
	items := []*string{&item}

	fmt.Printf("itemptr %p, itemptr %v", &item, items[0])
}

Output:

itemptr 0xc000014070, itemptr 0xc000014070
Program exited.