package mainimport("fmt")funcmain(){const name ="tom"fmt.Println(name)const tax float64=0.8fmt.Println(tax)}
go run const.go
tom
0.8
package mainimport("fmt")funcmain(){const a intfmt.Println(a)}
go run const.go
# command-line-arguments
./const.go:8:8: missing init exprfor a
package mainimport("fmt")funcgetVal(){fmt.Printf("测试")}funcmain(){const b =9/3fmt.Println(b)//const c = getVal()//fmt.Println(c)}
go run const.go
3
package mainimport("fmt")funcgetVal(){fmt.Printf("测试")}funcmain(){//const b = 9 / 3//fmt.Println(b)const c =getVal()fmt.Println(c)}
go run const.go
# command-line-arguments
./const.go:13:12: getVal()(no value) used as value
package mainimport("fmt")funcgetVal(){fmt.Printf("测试")}funcmain(){//const b = 9 / 3//fmt.Println(b)//const c = getVal()//fmt.Println(c)num :=9const b = num /3fmt.Println(b)}
go run const.go
# command-line-arguments
./const.go:16:12: num / 3(value of type int) is not constant