58 chars. ref #27

This commit is contained in:
Mark McGranaghan 2012-11-05 11:02:32 -08:00
parent ee7e950346
commit 363613d951

View File

@ -11,19 +11,22 @@ const s string = "constant"
func main() { func main() {
fmt.Println(s) fmt.Println(s)
// A `const` statement can appear anywhere a `var` statement can. // A `const` statement can appear anywhere a `var`
// statement can.
const n = 500000000 const n = 500000000
// Constant expressions perform arithmetic with arbitrary precision. // Constant expressions perform arithmetic with
// arbitrary precision.
const d = 3e20 / n const d = 3e20 / n
// A numeric constant has no type until it's given one, such as by // A numeric constant has no type until it's given
// an explicit cast. // one, such as by an explicit cast.
fmt.Println(int64(d)) fmt.Println(int64(d))
// A number can also be given a type by using it in a context that // A number can also be given a type by using it in a
// requires one, such as a variable assignment or function call. // context that requires one, such as a variable
// The type it gets depends on its value. // assignment or function call. The type it gets
// depends on its value.
fmt.Println(n) // int fmt.Println(n) // int
fmt.Println(d) // float64 fmt.Println(d) // float64
} }