Go Pointers


Go Pointers

This is a stub. Help our community expand it.

This quick style guide will help ensure your pull request gets accepted.

Pointers

Go has pointers. A pointer holds the memory address of a value.

The type *T is a pointer to a T value. Its zero value is nil.

var p *int

The & operator generates a pointer to its operand.

i := 42 p = &i

The * operator denotes the pointer’s underlying value.

fmt.Println(*p) // read i through the pointer p *p = 21 // set i through the pointer p

This is known as “dereferencing” or “indirecting”.

Unlike C, Go has no pointer arithmetic.

More Information:

This article needs improvement. You can help improve this article. You can also write similar articles and help the community.