func main() {
s := "a"
fmt.Println(&s, s)
s, i := "ab", 44 //s被重新赋值
fmt.Println(&s, s, &i, i)
{
s, i = "abc", 250
fmt.Println(&s, s, &i, i)
s := 1000 //在代码块中,s被重新定义
fmt.Println(&s, s)
}
s = "abcd"
fmt.Println(&s, s, &i, i)
}
显示结果
0xc208000150 a
0xc208000150 ab 0xc208000180 44
0xc208000150 abc 0xc208000180 250
0xc208000188 1000
0xc208000150 abcd 0xc208000180 250
有疑问加站长微信联系(非本文作者)