Skip to content

Instantly share code, notes, and snippets.

@hondajojo
Last active May 3, 2017 09:12
Show Gist options
  • Save hondajojo/f1b3e3c09d53771b3d86417a63f77a50 to your computer and use it in GitHub Desktop.
Save hondajojo/f1b3e3c09d53771b3d86417a63f77a50 to your computer and use it in GitHub Desktop.
go 指针
package main
import "fmt"
const MAX int = 3
func main() {
// 变量是一种使用方便的占位符,用于引用计算机内存地址。
// Go 语言的取地址符是 &,放到一个变量前使用就会返回相应变量的内存地址
// http://www.runoob.com/go/go-array-of-pointers.html
var a = "www" // 实际变量
var ip *string // 指针
ip = &a // 取变量的指针
fmt.Printf("变量的地址: %s\n", *ip) // *ip = *&a
var b = []int{0, 100, 10000} // 定义数组
var ipp [MAX]*int //整型指针数组
var i int
for i = 0; i < MAX; i++ {
ipp[i] = &b[i]
}
for i = 0; i < MAX; i++ {
fmt.Printf("%d\n", *ipp[i])
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment