RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
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://cqwzjz.cn/article/gooios.html