Go中变量的作用域-成都快上网建站

Go中变量的作用域


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中变量的作用域
文章分享:http://kswjz.com/article/gooios.html
扫二维码与项目经理沟通

我们在微信上24小时期待你的声音

解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流