Go语言中带前缀*的字符串

时间:2014-03-23 03:30:12

标签: string go

考虑一段Go代码:

var infile *string = flag.String("i", "infile", "File contains values for sorting")

我想知道*字符串在Go中意味着什么?

1 个答案:

答案 0 :(得分:5)

*前缀表示变量是指向字符串的指针而不是字符串的值。请参阅http://golang.org/doc/effective_go.html#pointers_vs_valueshttp://golang.org/ref/spec#Pointer_types

基本上,指针是某处某个值的内存引用。