I am new to the golang. Is it possible to mark a parameter as constant in function ? So that the parameter is not modified accidentally.
To declare a constant and give it a name, the const keyword is used. Constants cannot be declared using the := syntax.
A parameter is a quantity that influences the output or behavior of a mathematical object but is viewed as being held constant. Parameters are closely related to variables, and the difference is sometimes just a matter of perspective.
Declaring function parameters const indicates that the function promises not to change these values. In C, function arguments are passed by value rather than by reference. Although a function may change the values passed in, these changed values are discarded once the function returns.
In Go, constants provide complete safety in regards to the value they hold. They cannot be computed (making them used less often), but are guaranteed to always reference the same value.
No, this is currently not possible. There are several cases to distinguish:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With