Go - Pointer to pointer

If a pointer variable stores the address of another pointer variable, the pointer variable is called a pointer variable pointing to the pointer.

When defining a pointer variable that points to a pointer, the first pointer holds the address of the second pointer, and the second pointer holds the address of the variable:

The pointer variable declaration to the pointer is in the following format:

var ptr **< /span>int;

The pointer variable to the pointer above is an integer.

Accessing pointer variable values pointing to pointers requires two * signs, as follows:

package main

import "fmt"

func main() {

   var a int
   var ptr *int
   var pptr **int

   a = 3000

   /* pointer ptr address */
   ptr = &a

   /* Pointer to pointer ptr address */
   pptr = &ptr

   /* Get 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 pointer **pptr = %d\n", **pptr)

The above example execution output is:

variables a = 3000
Pointer Variables *ptr = 3000
Pointer pointer to pointer **pptr = 3000