How to print address of variable in golang?

Hi Friends 👋,

Welcome To aGuideHub! ❤️

Today, I’m going to show you how to print the memory address of variables in golang, here we will use the fmt.Printf() method to print data.

Golang provides %p to check the pointer address of any variable.

let’s write code.

package main
import "fmt"

func main() {
  r := []rune("abc");
  fmt.Printf("address of slice %p", &r)

when we run the above code, we get output something like address of slice 0xc42000a060 here 0xc42000a060 it’s the address of the r variable.

print, address of variable, golang

Try it yourself

All the best 👍

Follow me on Twitter