On Tuesday, 28 July 2015 at 22:52:31 UTC, Binarydepth wrote:
I'm reading the reference : http://dlang.org/arrays.html

And I'm declaring two dynamic arrays as I understand. What I had in mind was declaring a dynamic array of two elements each.

int[2][] is exactly an dynamic array of (arrays with the length 2), the logic behind this notation is:
1. Array of 2 int -> int[2]
2. a dynamic array of 1. -> int[2][] (like SomeType[] is an array of SomeType)


If you define SomeType e.g. as
struct SomeType {
 int firstElement;
 int secondElement;
}
you get something similar.

Yes, this is different from e.g. Java, where new int[2][42] creates an array of 2 arrays with 42 elements each.

Accessing int[2][] nums :
1. nums[5] is the 5th element of nums which is of type int[2]
2. nums[5][0] is the zeroth element of 5th element of nums
 int[2] tmp = nums[5];
 int value = tmp[0];
does the same...

Reply via email to