September 2017
Intermediate to advanced
466 pages
9h 33m
English
Pointers are memory addresses that offer improved speed in exchange for difficult-to-debug code and nasty bugs. C programmers know more about this. The use of pointer variables in Go functions is illustrated inside the pointers.go file, which can be divided into two main parts. The first part contains the definition of two functions and one new structure named complex:
func withPointer(x *int) {
*x = *x * *x
}
type complex struct {
x, y int
}
func newComplex(x, y int) *complex {
return &complex{x, y}
}
The second part illustrates the use of the previous definitions in the main() function:
func main() {
x := -2
withPointer(&x)
fmt.Println(x)
w := newComplex(4, -5)
fmt.Println(*w)
fmt.Println(w)
}
As the ...
Read now
Unlock full access