
变量是保存 *值* 的存储位置。允许值的集合由变量的 [*类型*](https://golang.org/ref/spec#Types) 决定。

 对于[变量声明](https://golang.org/ref/spec#Variable_declarations)或函数参数和结果，[函数声明](https://golang.org/ref/spec#Function_declarations)或[函数字面量](https://golang.org/ref/spec#Function_literals)的签名为指定的变量保存存储空间。调用内置函数 [`new`](https://golang.org/ref/spec#Allocation) 或获取[复合字面量](https://golang.org/ref/spec#Composite_literals)在运行时为变量分配存储空间。此类匿名变量是通过（可能是隐式的）[指针间接指引](https://golang.org/ref/spec#Address_operators).

*结构* 变量的[数组](https://golang.org/ref/spec#Array_types), [切片](https://golang.org/ref/spec#Slice_types)，和[结构](https://golang.org/ref/spec#Struct_types)具有可以单独[处理](https://golang.org/ref/spec#Address_operators)的元素和字段。每个这样的元素都像一个变量。





变量的 *静态类型* (或仅 *类型* )是其声明中给出的类型，`new` 调用或复合字面量中提供的类型或结构化变量的元素类型。接口类型的变量具有独特的 *动态类型* ，这是在运行时分配给变量的值的具体类型(除非该值是预先声明的标识符`nil`，没有类型)。动态类型在执行期间可能会有所不同，但是存储在接口变量中的值始终是该变量[可分配的](https://golang.org/ref/spec#Assignability)静态类型。

```go
var x interface{}  // x 为 nil 并且静态类型是 interface{}
var v *T           // v 的值为 nil, 静态类型是 *T
x = 42             // x 值为 42 并且动态类型是 int
x = v              // x 值为 (*T)(nil) 并且动态类型是 *T
```

通过在[表达式](https://golang.org/ref/spec#Expressions)中引用变量来检索变量的值；它是该变量[分配](https://golang.org/ref/spec#Assignments)的最新值。如果尚未为变量分配值，则其值为其类型的[零值](https://golang.org/ref/spec#The_zero_value)。