package main
import "fmt"
//声明全局变量可以 方法一、方法二、方法三;方法四只可用于局部变量
var fullInt = 400
var fullStr = "全局变量"
func main(){
//方法一:声明一个变量,默认值为0
var aInt int
var aStr string
fmt.Println("aInt =" , aInt,",aStr =",aStr,"-----")
//方法二:声明一个变量,初始化一个值
var bInt int = 100
var bStr string = "方法二"
fmt.Println("bInt =",bInt,",bStr =",bStr)
//方法三:在初始化时,可以省去数据类型,通过值自动匹配当前的数据类型
var cInt = 200
var cStr = "方法三"
fmt.Println("cInt =",cInt,",cStr =",cStr)
//方法四:省去var,直接用 :=
dInt := 300
fmt.Printf("type of dInt = %T\n",dInt)
dStr := "方法四"
fmt.Printf("type of dStr = %T\n",dStr)
dFloat := 3.1415 //float64 8个字节
fmt.Printf("type of dFloat = %T\n",dFloat)
dboolean := true
fmt.Printf("type of dboolean = %T\n",dboolean)
fmt.Println("dInt =",dInt,",dStr =",dStr,",dFloat =",dFloat,",dboolean =",dboolean)
//声明多个变量
var xx,yy int= 2,3
fmt.Println(xx,"--",yy)
var zz,aa = 2,"yyz"
fmt.Println(zz,"--",aa)
//多行多变量声明
var(
x1 int = 2
x2 string = "x2"
)
fmt.Println(x1,"--",x2)
var(
y1 = 3
y2 = true
)
fmt.Println(y1,"--",y2)
}