码迷,mamicode.com
首页 > 其他好文 > 详细

Go中变量的作用域

时间:2018-10-04 12:25:04      阅读:124      评论:0      收藏:0      [点我收藏+]

标签:func   变量声明   oat   \n   float   type   test   同名   全局   

package main import ( "fmt" ) //不同作用域同名变量 var a int //全局变量的声明 func test01(a float32) { fmt.Printf("a type = %T\n", a) } func main() { fmt.Printf("a type = %T\n", a) var a uint8 //局部变量声明 { var a float64 //局部变量声明 fmt.Printf("a type = %T\n", a) } fmt.Printf("a type =%T\n", a) test01(3.14) test02() } func test02() { fmt.Printf("a type = %T\n", a) }
//运行结果如下:
//a type = int
//a type = float64
//a type =uint8
//a type = float32
//a type = int

Go中变量的作用域

标签:func   变量声明   oat   \n   float   type   test   同名   全局   

原文地址:http://blog.51cto.com/13914991/2293799

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!