go-by-example/constants/constants.go
2023-12-18 03:40:05 -05:00

24 lines
No EOL
635 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package main
import (
"fmt"
"math"
)
//const declares a constant value.
const s string = "constant"
func main(){
fmt.Println(s)
// A const statement can appear anywhere a var statement can.
const n = 500000000
// Constant expressions perform arithmetic with arbitrary precision.
const d = 3e20 / n
// A numeric constant has no type until its given one, such as by an explicit conversion.
fmt.Println(int64(d))
// A number can be given a type by using it
// in a context that requires one, such
// as a variable assignment or function call.
// For example, here math.Sin expects a float64.
fmt.Println(math.Sin(n))
}