In Go, how do you declare a constant? Provide an example.
- const pi = 3.14159265359
- constant PI := 3.14
- final double PI = 3.14
- var PI float64 = 3.14
In Go, constants are declared using the const keyword followed by the constant name and its value. For example, const pi = 3.14159265359 declares a constant named pi with the value of π (pi). Constants in Go are immutable, and their values cannot be changed after declaration. They are typically used for values that should not change during the execution of a program, such as mathematical constants.
Loading...
Related Quiz
- Protocol Buffers in Go require the _____ command to generate Go code from a .proto file.
- Describe a scenario where using a map in Go would be more efficient than using a slice.
- _____ is a common Go library used to create RESTful APIs.
- How would you implement a timeout using channels?
- Describe a strategy to handle partial updates to resources in a RESTful API.