Creating Constant in Golang
Use Constant for variables that need no updation
Technofunnel presents another article on declaring constants in Golang, we will discuss about creating Constants in Golang and passing constants to functions. Every language provides capability to add constant and use them in application. Given below is the simple way to create constant is Golang.
In the above code we have created a simple const variable.
- We cannot use shorthand notation while creating constants
- We need not to define the type for the constant value.
In the below code, we can see that the shorthand notation does not work with constant values in Golang:
In the below code, we are specifying the type while creating the constant. Which results in error
Passing Constants to Golang Function
As seen in the previous articles, values are sent to function by value. When we are sending parameter to a function, a separate variable is created and the…