package main
import (
"fmt"
)
//不同作用域同名变量
var a int //全局变量的声明
func test01(a float32) {
fmt.Printf("a type = %Tn", a)
}
func main() {
fmt.Printf("a type = %Tn", a)
var a uint8 //局部变量声明
{
var a float64 //局部变量声明
fmt.Printf("a type = %Tn", a)
}
fmt.Printf("a type =%Tn", a)
test01(3.14)
test02()
}
func test02() {
fmt.Printf("a type = %Tn", a)
}
//运行结果如下:
//a type = int
//a type = float64
//a type =uint8
//a type = float32
//a type = int
《本文》有 2212 条评论