YouTip LogoYouTip

Go Pointer To Pointer

# Go Language Pointer to Pointer [![Image 4: Go Pointers](#)Go Pointers](#) If a pointer variable stores the address of another pointer variable, it is called a pointer to a pointer variable. When defining a pointer to a pointer variable, the first pointer stores the address of the second pointer, and the second pointer stores the address of the variable: !(#) The declaration format for a pointer to a pointer variable is as follows: var ptr **int; The above pointer to a pointer variable is of integer type. To access the value of a pointer to a pointer variable, you need to use two `*` signs, as shown below: 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 /* Get the value of pptr */ fmt.Printf("Variable a = %dn", a ) fmt.Printf("Pointer variable *ptr = %dn", *ptr ) fmt.Printf("Pointer to pointer variable **pptr = %dn", **pptr)} The output of the above example is: Variable a = 3000Pointer variable *ptr = 3000Pointer to pointer variable **pptr = 3000 [![Image 6: Go Pointers](#)Go Pointers](#)
← Go Array Of PointersGo Passing Arrays To Functions β†’