Multidimensional array

Oleksiy oleksiy.pavlyuk at gmail.com
Thu Jul 4 15:39:47 PDT 2013


Hi,

I'm new to the language and would appreciate if anybody could 
clarify the following:

1. What is the rationale behind "prefix declaration" of an array? 
Using right-to-left order to declare an array and left-to-right 
order to access elements seems confusing.

2. Consider this code:
     dchar[3][5] arr = '.';
     arr[2][] = '!';
     writeln();
     writeln(arr);

Result: ["...", "...", "!!!", "...", "..."]
Which is expected. According to Ali Çehreli's tutorial, omitting 
the index of an array will result in operation being applied to 
the whole array (in this case element of another array).

change the code:
-   arr[2][] = '!';
+   arr[][2] = '!';

Still getting the same result: ["...", "...", "!!!", "...", "..."]

I would expect to get: ["..!", "..!", "..!", "..!", "..!"]
since omitted index would apply the operation to all elements of 
the first dimension of the array.

What am I missing?


Thanks,
Oleksiy


More information about the Digitalmars-d-learn mailing list