0 votes
in GoLang by
What are constants in GOlang

1 Answer

0 votes
by

Constant variables are those variables whose value cannot be changed once assigned. A constant in Go programming language is declared by using the keyword “const”

Create a file called constant.go and with the following code

package main
import ("fmt")

func main() {
	const b =10
	fmt.Println(b)
	b = 30
	fmt.Println(b)
}

Execute go run constant.go to see the result as

.constant.go:7:4: cannot assign to b
...