acisola
acisola

Reputation: 103

How do I dereference a pointer in Go?

In the Go language, is there any way to convert *string to string? (or, for that matter, any *T to T?)

I have looked on the internet and through some Go documentation, but I can't find it - may have missed it.

Upvotes: 9

Views: 6303

Answers (1)

fuz
fuz

Reputation: 92966

To turn a *T into a T, use the * operator:

func Dereference(strptr *string) string {
    return *strptr
}

I highly suggest you to read about pointers before proceeding with the language. They are a fundamental concept without which it is impossible to use the language efficiently.

Upvotes: 9

Related Questions