How to initialize an array like int[][]
David L. Davis
SpottedTiger at yahoo.com
Tue Dec 5 17:57:08 PST 2006
Remember that you're doing loading a dynamic array, and not a static that
needs the static keyword.
// InitDynArray.d
// WinXP SP2, dmd v0.176
import std.stdio;
int main()
{
//int[2][3] b = [ [2,3], [6,5], [3,4] ];
int[][] b = [ [2,3], [6,5], [3,4] ];
for (int x = 0; x < 3; x++)
for(int y = 0; y < 2; y++)
writefln("b[%d][%d]=%d", x, y, b[x][y]);
return 0;
}
Output:
---------
C:\dmd>dmd initdynarray.d
C:\dmd\bin\..\..\dm\bin\link.exe initdynarray,,,user32+kernel32/noi;
C:\dmd>initdynarray
b[0][0]=2
b[0][1]=3
b[1][0]=6
b[1][1]=5
b[2][0]=3
b[2][1]=4
C:\dmd>
David L.
-------------------------------------------------------------------
"Dare to reach for the Stars...Dare to Dream, Build, and Achieve!"
-------------------------------------------------------------------
MKoD: http://spottedtiger.tripod.com/D_Language/D_Main_XP.html
"zhang" <zxpmyth at yahoo.com.cn> wrote in message
news:20061205235820.C47D.ZXPMYTH at yahoo.com.cn...
> In dmd/html/d/ctod.html, I see this:
> int[2][3] b = [ [2,3], [6,5], [3,4] ];
>
> However, when I put it into main(), I can't compile it using DMD 0.175 .
> To compile it successfully, I must change it to:
> static int[2][3] b = [ [2,3], [6,5], [3,4] ];
>
> But how this happens. Thans for any help!
>
More information about the Digitalmars-d-learn
mailing list