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.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *