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 👍

Premium Content

You can get all the below premium content directly in your mail when you subscribe us


Portfolio Template

View | Get Source Code

Cheat Sheets

Cheat Sheets Books are basically Important useful notes which we use in our day-to-day life.

I'm working on some more Cheat Sheets book on Jquery, TypeScript, React js and for other languages. I will send it once it's completed.

Related Posts