Constants
Go also has support for constants. Constants are essentially variables whose values cannot be changed later. They are created in the same way you create variables, but instead of using the var keyword we use the const keyword:
const x string = "Hello, World"
A const declaration defines named values that look syntactically like variables but whose value is constant, which prevents accidental (or nefarious) changes during program execution.
package main import "fmt" const ( x=10 y=20 z=30 ) func main(){ const name string ="John Carry" // Constant with data type fmt.Println(name) const age = 35 // Constant without data type fmt.Println(age) fmt.Println(x,y,z) }
The underlying type of every constant is a basic type: boolean, string, or number.
2017-01-26T14:11:40+05:30
2017-01-26T14:11:40+05:30
2017-01-26T14:11:40+05:30
Golang Constants
golang const enum, golang const struct, golang const iota, golang constant map, golang multiple constants, golang const array, const initializer is not a constant, golang const block
Amit Arora
Amit Arora
Constants
Golang Tutorial
Programming Tutorial