how to convert pointer to string in golang?

Hi Friends 👋,

Welcome To aGuideHub! ❤️

To convert pointer to string in golang, just assign pointer to another variable then you will able to see his value just make sure pointer is not nil.


Follow the below tutorial if you are struggling with installing GO in windows.

https://aguidehub.com/blog/how-to-install-golang-in-windows/


Today, I will show you how do I convert pointer to string in golang, as above mentioned I’m going to use assign pointer to another variable to get string.

Let’s start our Golang convert pointer to string example

main.go

package main

import "fmt"

func main() {
	var strPointer = new(string)
	*strPointer = "aGuideHub"

	strPointerValue := *strPointer
	fmt.Println(strPointerValue)
}

In the above example, we have converted type *pointer to string and printed in golang console. let’s check the output.

Output

aGuideHub

I hope it helps you, All the best 👍.

Try it Yourself

Premium Content

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

Books

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.

Stay tuned working on React Js Cheat Sheets Book

Related Posts