starting go by example
This commit is contained in:
26
5-go-by-example/4-constants.go
Normal file
26
5-go-by-example/4-constants.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
)
|
||||
|
||||
// const declares a constant value.
|
||||
const s string = "constant"
|
||||
|
||||
func main() {
|
||||
fmt.Println(s)
|
||||
|
||||
// can appear anywhere a var statement can
|
||||
const n = 500000000
|
||||
|
||||
// expressions perform arithmetic with arbitrary precision
|
||||
const d = 3e20 / n
|
||||
fmt.Println(d)
|
||||
|
||||
// numeric constants have no type until it’s given one
|
||||
fmt.Println(int64(d))
|
||||
|
||||
// numbers can be given a type by using it in a context that requires one
|
||||
fmt.Println(math.Sin(n))
|
||||
}
|
||||
Reference in New Issue
Block a user