Arrays passed by almost reference?
Ali Cehreli
acehreli at yahoo.com
Thu Nov 5 12:46:20 PST 2009
I haven't started reading Andrei's chapter on arrays yet. I hope I won't find out that the following behavior is expected. :)
import std.cstream;
void modify(int[] a)
{
a[0] = 1;
a ~= 2;
dout.writefln("During: ", a);
}
void main()
{
int[] a = [ 0 ];
dout.writefln("Before: ", a);
modify(a);
dout.writefln("After : ", a);
}
The output with dmd 2.035 is
Before: [0]
During: [1,2]
After : [1]
I don't understand arrays. :D
Ali
More information about the Digitalmars-d
mailing list