Does using "const" keyword for scalar parameters mean anything?

anonymous via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Jun 4 04:34:05 PDT 2015


On Thursday, 4 June 2015 at 11:28:51 UTC, tcak wrote:
> [code]
> void test( const int a ){}
> [/code]
>
> Does that "const" make any difference at all? At the end, it is 
> a scalar, and passed as value.

All it does is it makes the variable "a" const:
----
void test( const int a )
{
     a = 42; /* Error: cannot modify const expression a */
}
----

But the value is copied, yes. You can pass a mutable int in an 
immutable parameter and vice-versa.


More information about the Digitalmars-d-learn mailing list