> For the complete documentation index, see [llms.txt](https://denglj.gitbook.io/essential-go/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://denglj.gitbook.io/essential-go/06-pointers/dereferencing-pointers.md).

# 指针解引用(dereference)

可以在指针变量前面添加星号`*`来解引用。

```go
package main

import "fmt"

type Person struct {
	Name string
}

func main() {
	c := new(Person) // 返回指针
	c.Name = "Catherine"
	fmt.Println(c.Name) // prints: Catherine
	d := c
	d.Name = "Daniel"
	fmt.Println(c.Name) // prints: Daniel
	// 在指针前面添加星号以对指针解引用
	i := *d
	i.Name = "Ines"
	fmt.Println(c.Name) // prints: Daniel
	fmt.Println(d.Name) // prints: Daniel
	fmt.Println(i.Name) // prints: Ines
}

// 译者注，可以尝试打印c,d,i变量各自的地址和值看看
```

{% hint style="info" %}

#### 译者注

解引用(dereferencing)是指对指针引用的逆向操作。

通俗说，指针引用，就是我们在代码中玩儿的是指针(内存地址)，最关心的是内存地址和内存空间，而不那么关心空间里存了什么。

而指针解引用，就是让我们“揭开”内存地址这道引用隔膜，直接获取内存空间存放的东西。当然，内存空间中存放的仍然可以是指针(地址)。另外，解引用并非指“消除”或者“干掉”指针然后拿到值。

记住，指针等价于内存地址，而指针的名字相当于是内存地址的别名。故而，地址永远存在且不可被“干掉”，但是内存空间可以被释放，别名可以被删除。
{% endhint %}
