go语言之变量声明

时间:2014-10-07 19:06:03   收藏:0   阅读:176

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

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!