Accessing array elements with a pointer-to-array
Sergey
kornburn at yandex.ru
Fri Jan 26 12:02:23 UTC 2024
On Friday, 26 January 2024 at 11:38:39 UTC, Stephen Tashiro wrote:
> On Thursday, 25 January 2024 at 20:36:49 UTC, Kagamin wrote:
>> On Thursday, 25 January 2024 at 20:11:05 UTC, Stephen Tashiro
>> wrote:
>>> void main()
>>> {
>>> ulong [3][2] static_array = [ [0,1,2],[3,4,5] ];
>>> static_array[2][1] = 6;
>>> }
>>
>> The static array has length 2, so index 2 is out of bounds,
>> must be 0 or 1.
>
> I understand that the index 2 is out of bounds in an array of 2
> things. I'm confused about the notation for multidimensional
> arrays. I thought that the notation uint[m][n] is read from
> right to left, so it denotes n arrays of m things in each
> array. So I expected that static_array[k][j] would denotes the
> kth element of the jth array.
Yes, it is a bit tricky
Check this nice article if you are interested
https://tastyminerals.github.io/tasty-blog/dlang/2020/03/22/multidimensional_arrays_in_d.html
More information about the Digitalmars-d-learn
mailing list