up:: [[Golang MOC]] tags:: #on/computing/programming/languages/golang # Pointers in Go A *pointer* is a variable that stores the memory address of another variable. Declaring a pointer looks like this: ```go var a *int = &b ``` Where `*int` means that `a` is a pointer to an integer and `&b` means the address of `b`. > [!tip] > The zero value of a pointer is `nil`. ## The `new` Function Go has a function called `new` that is used to create pointers. This function takes a type as an argument and returns a pointer to a newly-allocated zero-value of the type passed as the argument. Take the following example: ```go ptr := new(int) ``` Here, `ptr` will be a pointer to an integer. That integer will be `0`, since that is the zero-value of type `int`. ## Dereferencing Pointers To dereference a pointer means to access the value of the variable it points to. The syntax for this is `*ptr`. ## References golangbot. “Pointers,” June 19, 2021. [https://golangbot.com/pointers/](https://golangbot.com/pointers/).