how to convert pointer to string in golang?
September 12, 2022Hi 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 👍.