Skip to content

Instantly share code, notes, and snippets.

@inancgumus
Last active October 11, 2017 16:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save inancgumus/05023157870c203038cef1419432c593 to your computer and use it in GitHub Desktop.
Save inancgumus/05023157870c203038cef1419432c593 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
)
func main() {
// typed constant declaration
const Pi float64 = 3.14
// multiple typed-constant declaration
const (
Tau float64 = Pi * 2
E float64 = 2.718
)
// there is no short-declaration for constants
// because, a constant always needs to be initialized to a value
fmt.Println("Pi:", Pi, "\nTau:", Tau, "\nE:", E)
// NOTE:
// above declarations are for demonstration purposes.
// you can define them as untyped constants
// the compiler will automatically assign float64 to them
//
// by using, for example, 3.14's default-type of float,
// it will convert it to usual float64 type.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment