# Pointers

A pointer holds the memory address of a value.

### Declaration

```go
var p *int         // *T means a pointer to a T value

i := 2
p = &i             // & operator generates a pointer to its operand

fmt.Println(*p)    // * operatos is used for dereferencing
*p = 21
```

{% hint style="info" %}
There is no pointer arithmetic in Go, unlike C.
{% endhint %}

### Example

```go
package main

import "fmt"

func main() {
    i, j := 18, 7799
    
    p := &i            // pointer to i
    fmt.Println(*p)    // read i from the pointer
    
    *p = 19            // change i from the pointer
    fmt.Println(i)
    
    p = &j             // re-assign the pointer to j
    *p = *p / 7
    fmt.Println(j)
}
```

```bash
18
19
1114
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://blog.yushunchen.com/golang-notes/official-tutorial-notes/more-types/pointers.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
