A Variable in which a value cannot be changed.
The ‘const’ keyword declares the variable as “constant”. That means it is unchangeable and read-only.
Syntax:
Const CONSTNAME type = value
Package main Import “fmt” Const PI=3.14 Func main() { Fmt.Println(PI) }
- Typed constants
Simple variable deceleration Go Lang program.
package main import "fmt" const X int = 10 func main() { fmt.Println(X) }
Output :
2.Untyped constants
Program to illustrate untyped variables.
package main import "fmt" const X = 11 //untyped constants/without a type func main() { fmt.Println(X) }
Output :
3.Program to illustrate mixed Constants.
package main import "fmt" const ( X int = 1 Y = 3343.4 Z = "Prwatech" ) func main() { fmt.Println(X) fmt.Println(Y) fmt.Println(Z) }
Output :
The post Go Constants appeared first on Prwatech.
This post first appeared on Learn Big Data Hadoop In Bangalore, please read the originial post: here