A pointer references a location in memory. Actually all memory addresses have the same type independently of the variable type as far as I understand.
Instead of using different pointer type (*int
, *string
etc..), is this possible using only one type (var p pointer
) for all the pointer types?
What is the difference between different pointer types?
package main
import "fmt"
func main() {
i := 5
s := "abc"
var pi *int // alternatively var pi pointer
var ps *string // alternatively var ps pointer
pi = &i
ps = &s
fmt.Printf("%p %p", pi, ps) // result is 0x1040e0f8 0x1040a120
}