Why does reverse also flips my other dynamic array?

Namal via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Sep 12 03:37:09 PDT 2015


import std.stdio;

void main(){

   int [] a = [1,2,3,4,5];
   int [] b = a;

	writeln(b, " ", a);
	a.reverse;
	writeln(b, " ", a);
}


I get:

[1, 2, 3, 4, 5] [1, 2, 3, 4, 5]
[5, 4, 3, 2, 1] [5, 4, 3, 2, 1]

Why is also b flipped here? This doesn't happen if I use static 
arrays.


More information about the Digitalmars-d-learn mailing list