Array declaration warning

Dennis Ritchie via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Jun 2 19:40:59 PDT 2015


I used to not even notice that if D declare an array in C-style, 
and then indexing it will also in C-style :)
Actually, I have a small question. And what is the advantage of 
indexing arrays D-style in front of a C-style arrays? Because 
C-style indexing is much more familiar: first, we point line, and 
then the columns.

import std.algorithm;

void main() {

     int cArr[2][4];
     assert(equal(cArr[], [[0, 0, 0, 0],
                           [0, 0, 0, 0]]));

     int[2][4] dArr;
     assert(equal(dArr[], [[0, 0],
			  [0, 0],
                           [0, 0],
                           [0, 0]]));
}


More information about the Digitalmars-d-learn mailing list