package main
/*
四种变量的声明方式
*/
import (
"fmt"
)
//声明全局变量 方法一、方法二、方法三是可以的
var gA int = 100
var gB = 200
//用方法四来声明全局变量
// := 只能够用在 函数体内来声明
//gC := 200
func main() {
//方法一:声明一个变量 默认的值是0
var a int
fmt.Println("a = ", a)
fmt.Printf("type of a = %T
", a)
//方法二:声明一个变量,初始化一个值
var b int = 100
fmt.Println("b = ", b)
fmt.Printf("type of b = %T
", b)
var bb string = "abcd"
fmt.Printf("bb = %s, type of bb = %T
", bb, bb)
//方法三:在初始化的时候,可以省去数据类型,通过值自动匹配当前的变量的数据类型
var c = 100
fmt.Println("c = ", c)
fmt.Printf("type of c = %T
", c)
var cc = "abcd"
fmt.Printf("cc = %s, type of cc = %T
", cc, cc)
//方法四:(常用的方法) 省去var关键字,直接自动匹配
e := 100
fmt.Println("e = ", e)
fmt.Printf("type of e = %T
", e)
f := "abcd"
fmt.Println("f = ", f)
fmt.Printf("type of f = %T
", f)
g := 3.14
fmt.Println("g = ", g)
fmt.Printf("type of g = %T
", g)
// =====
fmt.Println("gA = ", gA, ", gB = ", gB)
//fmt.Println("gC = ", gC)
// 声明多个变量
var xx, yy int = 100, 200
fmt.Println("xx = ", xx, ", yy = ", yy)
var kk, ll = 100, "Aceld"
fmt.Println("kk = ", kk, ", ll = ", ll)
//多行的多变量声明
var (
vv int = 100
jj bool = true
)
fmt.Println("vv = ", vv, ", jj = ", jj)
}