January 2018
Intermediate to advanced
340 pages
8h 6m
English
Go provides a pointer type that stores the memory location where data of a specific type is stored. Pointers can be used to pass a struct to a function by reference without creating a copy. This also allows a function to modify an object in-place.
There is no pointer arithmetic allowed in Go. Pointers are considered safe because Go does not even define the addition operator on the pointer type. They can only be used to reference an existing object.
This example demonstrates basic pointer usage. It first creates an integer, and then creates a pointer to the integer. It then prints out the data type of the pointer, the address stored in the pointer, and then the value of data being pointed at:
package mainimport ( "fmt" "reflect")
Read now
Unlock full access