Go language pointer to pointer
If a pointer variable holds the address of another pointer variable, the pointer variable is called a pointer variable that points to the pointer.
When defining a pointer variable that points to a pointer, the first pointerstores the address of the second pointer, and the second pointer stores theaddress of the variable:
The pointer variable declaration to the pointer is in the following format:
var ptr **int;
The pointer variable to the pointer above is an integer.
Accessing the value of a pointer variable pointing to a pointer requires theuse of two *
number, as follows:
package main
import "fmt"
func main() {
var a int
var ptr *int
var pptr **int
a = 3000
/* Pointer ptr address */
ptr = &a
/* Pointing to pointer ptr address */
pptr = &ptr
/* Obtain the value of pptr */
fmt.Printf("Variable a= %d\n", a )
fmt.Printf("Pointer variable * ptr = %d\n", *ptr )
fmt.Printf("Pointer variable pointing to a pointer **pptr = %d\n", **pptr)
}
The output of the above example is as follows:
Variable a= 3000
pointer variable *ptr = 3000
Pointer variable pointing to a pointer **pptr = 3000