Constants are declared are as follows
Some key points
A value should be assigned to a constant when it is declared
We cannot declare a constant and initialize it later.
Once a constant is created you cannot re-assign a value to that constant.
You cannot assign a value of a constant as a return value of a function, since the value of a constant is evaluated at compile time and methods are evaluated at runtime.
Implicit declaration syntax
Here the compiler will interpret the type as it runs to it
Output:
The following is an example for explicit declaration
This will throw .\main.go:8:25: constant 3.65 truncated to integer error

No comments:
Post a Comment