9

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.

1 Answer 1

9

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.

Sign up to request clarification or add additional context in comments.

2 Comments

@acsiola, note that, of course, there's no need to write a function to dereference pointers -- it was provided solely for the purpose of demonstration.
@kostix, Yes, I noticed. Thank you! :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.