Referenced Variables As Parameters
Explore how variables passed as references in D functions affect the original data, including slices and associative arrays. Understand when changes impact the original variables and when passing by reference is necessary to avoid unexpected behaviors.
Referenced variables are not copied
Even parameters of reference types like slices, associative arrays and class variables are copied to functions. However, the original variables that are referenced (i.e. elements of slices and associative arrays and class objects) are not copied. Effectively, such variables are passed to functions as references; the parameter becomes another reference to the original object. It means that a modification made through the reference modifies the original object as well.
Since strings are slices made up of characters, this ...